简体   繁体   English

是否可以在Chrome打包的应用中执行JavaScript文件?

[英]Is it possible to execute a JavaScript file in a chrome packaged app?

I am trying to make a Box2D TestBed structure in a Chrome app using kripken's Box2D.js . 我正在尝试使用kripken的Box2D.js在Chrome应用中创建 Box2D TestBed结构。 I have successfully gotten the testbed built and working you can download it from here . 我已经成功建立了测试平台, 可以在这里下载它 One of the features I would like to add to the testbed is the ability to load JavaScript files at runtime. 我想添加到测试平台的功能之一是能够在运行时加载JavaScript文件。 Since chrome apps can't use eval is there any way of loading a JavaScript file at runtime? 由于chrome应用程序无法使用eval ,有什么方法可以在运行时加载JavaScript文件吗? I've tried using $.getScript with a file:/// URL and the appropriate permissions but that doesn't work. 我尝试将$.getScriptfile:/// URL和适当的权限一起使用,但这不起作用。 Here are some example files that I would like to load at runtime. 这是一些我想在运行时加载的示例文件。 This is very frustrating since the program can be run on the web but not in a chrome app! 由于该程序可以在Web上运行,但不能在chrome应用程序中运行,这非常令人沮丧!

UPDATE: 更新:

I've tried using a chrome sandbox to do the evaling but I cannot pass functions through window.postMessage . 我曾尝试使用chrome沙箱进行回避,但无法通过window.postMessage传递函数。 I'm beginning to lean towards hosting it on a server. 我开始倾向于将其托管在服务器上。

Thanks! 谢谢!

You should be able to load external scripts. 您应该能够加载外部脚本。 There's a catch though; 不过有一个陷阱。 you'll have to do it in a sandboxed page that doesn't have any access to the chrome.* APIs. 您将不得不在无法访问chrome。* API的沙盒页面中执行此操作。 But you can communicate with this page through window.postMessage 但是您可以通过window.postMessage与该页面进行通信

See http://developer.chrome.com/apps/app_external.html 请参阅http://developer.chrome.com/apps/app_external.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM