作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在contentscript.js中使用javascript文件的功能?我在 a1.js 中有一些函数,我想知道如何在 contentscript.js 中调用它们
a1.js 也是扩展的一部分,与 contentscript.js 在同一个文件夹中
最佳答案
将它们放入您的 manifest.json
文件中:
....
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["a1.js", "contentscript.js"]
}
],
....
a1.js
将首先加载,然后是 contentscript.js
。
例子:
// a1.js
function x() { return 100; }
alert(typeof y); // undefined, because `contentscript.js` is not loaded yet
setTimeout( function(){alert(typeof y;)}, 1000 ); // function
// contentscript.js
function y() {
alert(x()); // Shows 100
}
关于javascript - 如何在 Chrome 扩展中使用另一个 javascript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9250185/
我是一名优秀的程序员,十分优秀!