Hmm... I do understand your predicament (wanting the dynamically-loaded script to use the right version of jQuery). I'm trying to imagine situations where your change could cause potential problems, but I'm not sure, yet.
FWIW, this problem also affects getScript when pulling scripts from an outside domain (and it can't be fixed used the technique described here since there's no window of opportunity where the global jQuery variable could be changed). I also note that you only change 'jQuery' and not '$' - it seems like both would be necessary, in this case. But, again, I'm worried about the external affects of manipulating the global variables. --John On Wed, Apr 22, 2009 at 1:04 PM, Mark Gibson <[email protected]> wrote: > > Hi, I'm using jQuery in a high conflict situation, ie. multiple > versions of jQuery in one page. > Unfortunately I have no way around this other than not using the latest > jQuery. > > So first off, jQuery 1.2 is loaded and noConflict() called. > Later, jQuery 1.3.2 is loaded and fed into a closure as such: > > (function($) { > ... > })( jQuery.noConflict(true) ); > > Within the closure if I try to dynamically load some html that > contains script then the script will be executed with jQuery 1.2 as > the global jQuery object. > I believe it would be more appropriate to temporarily set the global > jQuery to the one loading the script, ie. 1.3.2 in this case. > > I've got two demo's, first without the patch, second with the patch: > > http://test3.internal.adaptavist.net/~mgibson/versions/load1.html > http://test3.internal.adaptavist.net/~mgibson/versions/load2.html > > It this worth considering, shall I raise a ticket? > > > Here's the patch: > > Index: src/core.js > =================================================================== > --- src/core.js (revision 6319) > +++ src/core.js (working copy) > @@ -290,7 +290,10 @@ > // Inspired by code by Andrea Giammarchi > // > http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html > var head = document.getElementsByTagName("head")[0] || > document.documentElement, > - script = document.createElement("script"); > + script = document.createElement("script"), > + globaljQuery = window.jQuery; > + > + window.jQuery = jQuery; > > script.type = "text/javascript"; > if ( jQuery.support.scriptEval ) { > @@ -303,6 +306,8 @@ > // This arises when a base node is used (#2709). > head.insertBefore( script, head.firstChild ); > head.removeChild( script ); > + > + window.jQuery = globaljQuery; > } > }, > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---
