Chris
2010-05-21 09:39:08
A:
You can do something like this:
$(function() {
if($('#yourscriptid').length == 0) {
document.getElementsByTagName('head').item(0).innerHTML+='<script id="yourscriptid" type="text/javascript" src="path/to/script"></script>';
}
});
Felix Kling
2010-05-21 09:45:32
+1
A:
Well if that JavaScript file defines a specific variable (or a function) you can check its presence by checking typeof that_variable
, then load the JavaScript file if necessary. An example, here is how you load swfobject library if its not available on the page:
if (typeof swfobject == "undefined") {
var e = document.createElement("script");
e.src = "http://ajax.googleapis.com/ajax/libs/swfobject/2/swfobject.js";
e.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(e);
}
Salman A
2010-05-21 13:59:09