Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing jQuery 1.4 in GreaseMonkey while the original page uses jQuery 1.3 (different version)?
    text
    copied!<p>What is the best strategy to supply a necessary new version of jQuery (1.4.2) in a userscript, which modifies a page that already has an older version of jQuery (1.3.1)? </p> <p>Preferably the original page continues to use '$' sign while in my script it uses an alias assigned by <code>jquery.noConflict()</code>.</p> <p>According to the answer to <a href="https://stackoverflow.com/questions/528241/how-do-i-run-different-versions-of-jquery-on-the-same-page">this question</a>, any extra version one wishes to load should be placed above the original script tag. This is where I get a little confused, since I'm under the impression GreaseMonkey executes the script after page loads? </p> <p><strong>EDIT:</strong> One thought is in the userscript, append a script tag for jQuery 1.4.2, set alias, then append a script tag for 1.3.1 again so as to not break the original page's code, which uses 1.3.1 functions.</p> <pre><code>var code142 = function() { gj = jQuery.noConflict(true); alert("142..."); alert(gj); // check if the dollar (jquery) function works alert(gj().jquery); // check jQuery version } var script = document.createElement("script"); script.src = 'http://code.jquery.com/jquery-1.4.2.min.js' document.documentElement.appendChild(script); // assign jquery object alias and run code that uses 1.4.2 there var script = document.createElement("script"); script.textContent = '(' + code142.toString() + ')();'; document.documentElement.appendChild(script); /* The following is perhaps redundant, see EDIT 2 for more info // add jquery 1.3.1 (again) var script = document.createElement("script"); script.src = 'http://code.jquery.com/jquery-1.3.1.min.js' document.documentElement.appendChild(script); */ </code></pre> <p>But this will require loading the jQuery library 3 times per page. Is there any better way?</p> <p><strong>EDIT 2:</strong> It seems the original page could still use its 1.3.1 copy, despite that the GM script has supplied a 1.4.2 copy, they can co-exist just as long as I use the new alias (<code>gj</code>) to refer to the 1.4.2 jQuery object inside <code>code142()</code>.</p> <p>If nothing else comes up then this would be my solution. I hope it's useful to other folks who may run into this problem.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload