3

I'm creating some JavaScript, mainly jQuery based widgets that are suppose to work on third-party pages. To simplify embedding and maintenance of the widgets, we are asking users to embed only one <script> element snippet that downloads a JavaScript file from our server which further downloads all the CSS and JavaScript needed for widget to run, and places them in head of the third-party page.

My problem happens with pages that already have jQuery, which is one of the dependent JavaScript. Our widget uses var jQuery_1_6 = jQuery.noConflict(true) which is set right after jQuery is loaded, however, in the script that check whether jQuery is loaded we use the following if (typeof jQuery == 'undefined') and if (typeof jQuery.ui == 'undefined').

Now the thing is if there is already jQuery and jQuery.ui on the page, the ifs will not load jQuery version, which (I guess) causes jQuery_1_6 = jQuery.noConflict(true) not to work.

Any ideas how to apply noConflict on already loaded jQuery? Would it help to append again the nodes that already loaded jQuery, and if so, how to figure out which .js file hosts jQuery code?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Master Slave
  • 27,771
  • 4
  • 57
  • 55
  • see: http://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-page – Manuel van Rijn Oct 18 '11 at 11:13
  • Hi Manuel, just to respect you effort as weel, the difference between the thread you suggested and what I need is, that we don't require users to add any script elements in head, rather we load it dynamically, which results in the problem I described. Thank you anyhow, best – Master Slave Oct 20 '11 at 08:55

1 Answers1

3

Try this

http://alexmarandon.com/articles/web_widget_jquery/

sathis
  • 547
  • 1
  • 3
  • 21
  • 1
    Wow, nailed it right in the head. It is exactly what I'm doing. Thanks Sathis. By the way, my first question on stackoverflow, I'm pretty impressed. – Master Slave Oct 18 '11 at 12:34