@ require-ing jQuery会覆盖页面的$变量 [英] @require-ing jQuery overwrites the page's $ variable

查看:54
本文介绍了@ require-ing jQuery会覆盖页面的$变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的Greasemonkey脚本@require -ing jQuery,并在脚本文件中添加以下行:

I'm @require-ing jQuery for my Greasemonkey script with this line in my script file:

// @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js

,并且效果很好;我可以使用$('#id')来访问DOM.

and it works quite well; I can use $('#id') to access the DOM.

但是,修改了真实"页面的$变量(其中$是jQuery 1.2.xx): 我收到未定义$.include的错误.

However, the $ variable of the 'real' page is modified (where $ is jQuery 1.2.xx): I get an error that $.include is not defined.

我以为Greasemonkey的沙箱模型可以防止目标页面的变量被覆盖?

I thought the sandbox model of Greasemonkey would prevent that the variables of the target-page are overwritten?

如何确保包含javascript库不会影响真实"网站,而只会影响我的Greasemonkey脚本?

How can I ensure that the inclusion of javascript libraries does not affect the 'real' website, but only my Greasemonkey script?

推荐答案

Greasemonkey 1.0,从根本上改变了沙盒有效,破坏了数千个脚本.另请参见, Greasemonkey 1.0中的jQuery与使用jQuery的网站冲突.

Greasemonkey 1.0, radically changed the way the sandbox works, busting thousands of scripts. See also, jQuery in Greasemonkey 1.0 conflicts with websites using jQuery.

这是一个巨大的问题,我希望您能与我一起发表您对此问题的主要错误报告.

This is a huge problem, and I hope you will join me in voicing your opinion/experiences on the principle bug report for this issue.

同时,通过编辑 元数据块以以下几行结尾:

Meanwhile, restore the sandbox to your script, and resolve the $ conflict, by editing your Metadata Block to end with the following lines:

// @grant       GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a major design change introduced in GM 1.0,
    It restores the sandbox.
*/


指定@grant值(none除外)会重新激活沙箱.


Specifying a @grant value (other than none) reactivates the sandbox.

您还可以考虑切换到 Scriptish ,该语言具有过去提供了卓越的功能和性能,并且不受这种新的沙箱行为的影响.

You might also consider switching to Scriptish, which has offered superior features and performance in the past, and does not suffer from this new sandbox behavior.

这篇关于@ require-ing jQuery会覆盖页面的$变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆