是的,这是完全可能的,而且很容易。这是一个工作示例。尝试从此开始,确认它可以工作,然后重新添加您自己的代码。如果您遇到障碍,并且提出了比XHR是否在打包应用程序中工作更具体的问题,那么您可能想问一个新问题。
manifest.json:
{ "name": "SO 15977151 for EggCup", "description": "Demonstrates local XHR", "manifest_version" : 2, "version" : "0.1", "app" : { "background" : { "scripts" : ["background.js"] } }, "permissions" : []}
background.js:
chrome.app.runtime.onLaunched.addListener(function() { chrome.app.window.create("window.html", { bounds: { width: 600, height: 400 }});});
window.html:
<html><body> <div>The content is "<span id="content"/>"</div> <script src="main.js"></script></body></html>
main.js:
function requestListener() { document.querySelector("#content").innerHTML = this.responseText;};onload = function() { var request = new XMLHttpRequest(); request.onload = requestListener; request.open("GET", "content.txt", true); request.send();};
content.txt:
Hello, world!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)