在目标页面上访问jQuery的现有副本 [英] Access an existing copy of jQuery on the target page
本文介绍了在目标页面上访问jQuery的现有副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个小的用户脚本来从服务器获取一些内容并将其添加到绑定中。
该站点具有jQuery,我怎样才能使用该站点的jQuery而不是 @require
(因为Chrome现在不支持此功能)?
I am writing a small userscript to get some content from a server and add it to a tie.
The site has jQuery, how can I just use the site's jQuery instead of @require
(because Chrome doesn't support this now)?
推荐答案
使用 现有 的jQuery副本,代码如下:
Use an existing copy of jQuery with code like this:
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的现有副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文