【发布时间】:2013-01-26 20:47:15
【问题描述】:
我编写了用户脚本,但我在 Chrome 中遇到了问题(带有 Greasemonkey 的 Firefox 可以): 我使用 Tampermonkey;这是代码:
// Header...
(function addjQuery() {
var head = document.getElementsByTagName('head')[0] ;
var jQuery = document.createElement('script');
jQuery.type = 'text/javascript';
jQuery.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
head.appendChild(jQuery);
waitjQuery() ;
})();
function waitjQuery(){
typeof jQuery == 'undefined' ? setTimeout(waitjQuery, 50) : main() ;
}
我的脚本在函数等待中循环,typeof jQuery(或 $...)始终未定义。我已经使用控制台检查了页面 HTML 的头部,并且 jQuery 已正确加载...
【问题讨论】:
-
这在这里工作...jsfiddle.net/ACWsP您的控制台日志中有任何错误吗?你确定它没有在
Main()的某个地方循环吗? -
日志中没有错误,并且可以确定在 waitJquery 中我在使用此功能时会出现“警报”循环...
标签: javascript jquery google-chrome tampermonkey