我安装了 Google Chrome 扩展 cjs(网站自定义 JavaScript)。
如果我在 cjs 编辑器中编写脚本,则脚本工作正常:
我在 js 文件中编写了脚本并将其放入我的 IIS 中,如下所示:
- 打开 IIS 管理器
- 右键单击“默认网站”
- 添加应用
- 别名 = googleScript
- 物理路径:C:\scripts\google(例如)
- 我创建了一个 googleScript.js 文件并将其保存在 C:\scripts\google 中。文件内容为:alert("Google");
- 我点击“连接为”并选择应用程序用户(直通身份验证)
- 我打开了位于 googleScript(在 IIS 中)的默认文档,并添加了一个名为:googleScript.js 的新默认文档
- 当我右键单击 googleScript 并选择管理应用程序->浏览时,将使用我编写的脚本打开一个新网页。该页面的 URL 为 http://localhost/googleScript/
- 现在回到 cjs 扩展,而不是 alert("Google"); 我编写了 //localhost/googleScript/googleScript.js;。
调用脚本文件时,警报不再起作用。从 cjs chrome 扩展调用脚本文件的正确方法是什么?
最佳答案
阅读
在继续之前...
<小时/>我创建了一个小weave您可以在您的应用程序/扩展中尝试这个想法。
现在,这是在线获取和保存外部脚本源的一种方法。
var download_to_textbox = function (url, el) {
return $.get(url, null, function (data) {
el.val(data)
}, "text")
};
获取脚本源代码并将其添加到文本区域
download_to_textbox('libraries/alertifyjs/css/alertify.min.css', $('.alertifyjs1'));
使用 FileSaver.js 保存文件 - https://github.com/eligrey/FileSaver.js/
var blob = new Blob([ $('.alertifyjs1').val() ], {type: "text/html"});
saveAs(blob, "alertify.min.css");
关于javascript - 如何从cjs chrome扩展读取js脚本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36711512/