eozzy
eozzy

Reputation: 68790

Loading JS dynamically from another JS (jQuery)

I'd like to know if I can load an external JS dynamically based on some condition, for example:

$(window).load(function () {
   if($.browser.msie && $.browser.version=="6.0") {
     // load ie.js
     // do stuff using ie.js
   }
});

Upvotes: 1

Views: 765

Answers (3)

Nrj
Nrj

Reputation: 6841

If not using jquery, use this to include js

document.writeln('<script type="text/javascript" src="your.js"></script>');

Upvotes: 3

avpaderno
avpaderno

Reputation: 29749

Use $.getScript(url,callback); it loads the script, and executes it.

Upvotes: 0

Michael La Voie
Michael La Voie

Reputation: 27926

JQuery's GetScript should do it.

$.getScript("yourscirpt.js", function() {
    alert('Load Complete');
});

Upvotes: 4

Related Questions