- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个包含 content_script
的小型 Chrome 扩展程序。
它将在单个域上运行,我正在尝试稍微改进一个站点。
我想在我的内容脚本中使用 jQuery
,但是网站也使用 jQuery
,所以我不能简单地将 jQuery 添加到我的扩展程序的 content_script
数组。
我的 content_script
将
"run_at": "document_end"
但是 jQuery
还没有加载。它也没有在 document_idle
上加载。
所以我必须等待。
我该怎么做?
我试过这样做:
(function() {
var i = setInterval(function () {
console.log(typeof jQuery + " " + i);
if (typeof jQuery != "undefined") {
console.log("jQuery loaded");
clearInterval(i);
} else {
console.log("jQuery not loaded");
}
}, 200);
})();
但由于某些原因,typeof jQuery
在该循环中始终未定义。
如果我手动 clearInterval
,并检查 typeof jQuery
,我会正确地得到 “function”
。
( Chrome 检查员控制台)
有什么想法吗?
编辑:content_script
是特殊的:
Content scripts are JavaScript files that run in the context of web pages. By using the standard Document Object Model (DOM), they can read details of the web pages the browser visits, or make changes to them.
最佳答案
I cannot simply add jQuery to my extension's
content_script
array.
你可以而且应该。扩展变量空间是沙盒化的,因此内容脚本无法从父页面访问变量,反之亦然。
关于google-chrome - Chrome content_script : How to wait for jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6945382/
我是一名优秀的程序员,十分优秀!