How to use jquery in the contents of a chrome extension script when an older version is already on the page

I am writing a chrome extension that unfolds with a page layout. I want to use the latest jQuery version for this.

Version 1.4.4 jQuery is already included in this page as part of one of their scripts.

If I include a newer version of jQuery, the page freezes. How to enable the new version of jQuery so that it is available only to my script content and does not affect scripts already on the page?

+8
javascript jquery google-chrome-extension
source share
2 answers

If you enter your jquery as the contents of the script, it will be an isolated sandbox , you will have no conflicts, no matter what the parent page is.

+6
source share

You can essentially namespaces differing in jQuery versions using No Conflict mode and executing your code in closure. For example:

<script src="jquery-1.6.2.min.js" type="text/javascript"></script> <script type="text/javascript"> jq162 = jQuery.noConflict(true); (function ($) { $(function () { // Your document ready code here }); })(jq162); </script> 

Please note that this declaration makes jq162 available to the global realm, so it can be reused elsewhere. If you prefer to locally localize the jQuery instance, make it var .

+1
source share

All Articles