在目标页面上访问jQuery的现有副本
我正在编写一个小的用户脚本,以便从服务器获取一些内容并将其添加到tie中。在目标页面上访问jQuery的现有副本,jquery,google-chrome,greasemonkey,userscripts,Jquery,Google Chrome,Greasemonkey,Userscripts,我正在编写一个小的用户脚本,以便从服务器获取一些内容并将其添加到tie中。 网站有jQuery,我怎么能只用网站的jQuery而不是@require(因为Chrome现在不支持这个)?使用一个现有的jQuery副本,代码如下: function main () { /*--- Put all of your code here. Use jquery with $ or however the target page uses it. */ } function
网站有jQuery,我怎么能只用网站的jQuery而不是
@require
(因为Chrome现在不支持这个)?使用一个现有的jQuery副本,代码如下:
function main () {
/*--- Put all of your code here.
Use jquery with $ or however the target page uses it.
*/
}
function addJS_Node (text, s_URL, funcToRun) {
var D = document;
var scriptNode = D.createElement ('script');
scriptNode.type = "text/javascript";
if (text) scriptNode.textContent = text;
if (s_URL) scriptNode.src = s_URL;
if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
targ.appendChild (scriptNode);
}
addJS_Node (null, null, main);
使用jQuery的现有副本,代码如下:
function main () {
/*--- Put all of your code here.
Use jquery with $ or however the target page uses it.
*/
}
function addJS_Node (text, s_URL, funcToRun) {
var D = document;
var scriptNode = D.createElement ('script');
scriptNode.type = "text/javascript";
if (text) scriptNode.textContent = text;
if (s_URL) scriptNode.src = s_URL;
if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
targ.appendChild (scriptNode);
}
addJS_Node (null, null, main);
你能使用unsafeWindow.jQuery吗?陷阱,不
unsafeWindow
是为Chrome内容脚本提供的,但工作方式不同。除了标准DOM之外,它不允许访问JS对象。另请参见:and。您可以使用unsafeWindow.jQuery
?陷阱,不unsafeWindow
是为Chrome内容脚本提供的,但工作方式不同。除标准DOM外,它不允许访问JS对象。另请参见:和。