开发者

Mixing jQuery versions

I have a script i insert in to an HTML page when it is browsed. My script uses the latest version of jQuery and i am running in to issues with people that already have an older version of jQuery declared on their page. I have been re-assigning my jQuery object to my own varialbe to avoid the conflict, but i am wondering: Is it possible to insert j开发者_开发问答Query in to my own object without having to re-assign variable? I mean going from something like:

var myJquery = jQuery.noConflict(true);

to something like

myCustomObject.prototype.jQuery = //how do i populate this?

myCustomObject.jQuery.blahblah();

Im am wanting my version of jQuery to be a member of my javascript object.


If you're including jQuery core without modifying it, you can't do this...it overwrites the window.jQuery object itself, that's where the issues start. Number one example: redeclaring window.jQuery and by proxy window.jQuery.prototype you erase all plugins in the page.

Check if window.jQuery exists before including it...otherwise you need to change jQuery core, in particular this line:

return (window.jQuery = window.$ = jQuery);

To something like:

return (myCustomObject.jQuery = jQuery);

In that context the jQuery on the end is a variable local the scope at that point, not yet screwing up much.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜