jQuery / Prototype 冲突:仅在 webkit、bookmarklet 中
我很可能遇到与此问题相同的问题:
基本上,Prototype 似乎与 Safari 和 Chrome 中的 jQuery 发生冲突。问题中的解决方案是首先包含原型,但是我不能这样做:我正在使用在我的书签中加载的 jQuery,因此使用它的某些网站将始终已加载原型。现在让我们暂时忽略在小书签中使用 jQuery 的智慧。在我看来,这里应该有一个解决方案(虽然我找不到它),原因如下:
1)这种冲突在 Firefox 中似乎根本不会发生。 2)虽然上面链接的问题引用了一个页面,规定应该首先包含 jQuery,但我不再在那里找到该引用。那么也许它不是当前的?
错误示例:一旦加载 jQuery(例如,您可以测试它的版本 -1.4.4),如果您在 firebug 控制台中尝试:
jQuery('p:')
#yields => []
#or
jQuery('p:first')
# yields => TypeError: Object #<an Object> has no method 'find'
其他一些注意事项: -我尝试过noConflict()。这似乎根本不起作用。
-我从不在代码中引用“$”,而只使用“jQuery” -使用来自 Google CDN 的 jQuery - 如果可能的话,将所有小书签代码移至框架中将非常困难,所以我宁愿不去那里。
感谢您的帮助!
I most likely have the same problem as in this question:
Weird Chrome prototype/jQuery conflict
Basically it appears Prototype is conflicting with jQuery in Safari and Chrome. The solution in the question was to include prototype first, however I can't do that: I'm using jQuery loaded in my bookmarklet, and so some sites it is used on will always have Prototype already loaded. Now let's ignore for the moment the wisdom of using jQuery in the bookmarklet. It seems to me there should be a solution here (though I can't find it), for these reasons:
1) This conflict does not appear to occur at all in Firefox.
2) Though the question linked to above cites a page stipulating that jQuery should be included first, I no longer find that reference there. So maybe it is not current?
Error Example: once jQuery is loaded (e.g. you can test it's version -1.4.4), if you try in the firebug console:
jQuery('p:')
#yields => []
#or
jQuery('p:first')
# yields => TypeError: Object #<an Object> has no method 'find'
Some other notes:
-I have tried noConflict(). This does not seem to work at all.
-I never refer to '$' in my code, but only use 'jQuery'
-Using jQuery from the Google CDN
-Moving all the bookmarklet code into a frame would be very difficult, if possible at all, so I'd rather not go there.
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我必须为一个客户项目执行此操作,并遇到了完全相同的问题。经过一些研究,看起来冲突在 1.4.2 中不存在,但在 1.4.3 中存在(我不确定以后的版本)。我降级到 1.4.2,我的书签现在可以在带有 Prototype 的页面上运行。
第三条评论:
http://forum.jquery.com /topic/jquery-conflicts-with-prototype-and-the-fix
I had to do this for a client project, and ran into the exact same issue. After some research it looks like the conflict doesn't exist in 1.4.2, but does in 1.4.3 (I'm not sure about later versions). I downgraded to 1.4.2 and my bookmarklet now works on pages with Prototype.
Third comment here:
http://forum.jquery.com/topic/jquery-conflicts-with-prototype-and-the-fix
我相信这个问题现在已经在 jquery 1.5+ 中修复了......
I believe that this is now fixed in jquery 1.5+ ....