Deh*_*zer 6 javascript c++ google-chrome google-chrome-extension google-nativeclient
我有一个网站和谷歌浏览器扩展程序.扩展使用NaCl API(JavaScript)从用户的计算机写入/读取文件(C++).
我的问题是:我可以在我的网站中加载我的扩展程序,例如,在iFrame中保存其功能吗?
我试图这样做,但它只加载扩展"视觉"部分.写/读(NaCl)功能不起作用.
一个更好地解释我想做的事情的例子:
它实际上是这样工作的:

我想这样做:

或者另一种方式,但我认为这不可能,是吗?

可能吗?我该怎么做?
编辑
这是代码:
在manifest.json中,我把它放在:
"externally_connectable": {
"matches": ["http://www.example.com/index.html"]
},
"web_accessible_resources": [
"/*"
],
"content_scripts" : [
{
"matches" : ["http://www.example.com/index.html"],
"js": ["index.js"]
}
],
Run Code Online (Sandbox Code Playgroud)
我的网站的iframe:
<iframe src="chrome-extension://myextensionid/index.html"></iframe>
Run Code Online (Sandbox Code Playgroud)
在我的扩展index.js文件中,只有两个按钮.它们的函数(JavaScript)与.cc文件(通过NaCl)进行通信,以将字符串保存或加载到计算机上的文件中.
正如我所说,扩展工作正常,但当我尝试通过iframe在我的网站加载它时,它只加载html(可视).只要JS使用NaCl调用C++函数,JavaScript就不会加载C++.
有解决方案吗
<embed name="nacl_module" id="nacl_module" width="100%" height="100%" path src="//storage.googleapis.com/gonacl/demos/publish/236779/voronoi/voronoi.nmf" type="application/x-pnacl">
Run Code Online (Sandbox Code Playgroud)
上面的标签在这个 iframe 中:
<iframe frameborder="0" width="100%" height="100%" src="/static/voronoi/index.html">
Run Code Online (Sandbox Code Playgroud)
这是来自https://gonativeclient.appspot.com/demo/voronoi
此外,https://gonativeclient.appspot.com/static/voronoi/example.js包含如何完成此操作的脚本。
我已经搜索了 10 分钟才找到它。只是要知道 NaCl 无法在其他浏览器上运行。
如果你想要可以在所有浏览器上运行的纯 JavaScript。使用下面的代码片段。它创建一个链接,当您单击它时,它会下载一个包含text数据的文本文件。添加“.innerHTML”属性,例如“保存”,然后您可以单击它。HTML5对长属性没有限制。
var file = document.createElement('a');
file.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
file.setAttribute('download', filename);
Run Code Online (Sandbox Code Playgroud)
您可以text从多行文本框并使用更新其值的键事件来设置变量。文件名也是如此,例如“Saved Draft.txt”。除了文本/纯文本之外,您还可以尝试其他类型的数据。要检查其他类型,请搜索标头在其数据字段中可以采用的内容。
对于文件加载,您可以检查此http://www.html5rocks.com/en/tutorials/file/dndfiles/
| 归档时间: |
|
| 查看次数: |
991 次 |
| 最近记录: |