Reputation: 155
I have written a code to add script at run time but that code is not working in safari browser. My code is given below.
var head = document.head;
var script = document.createElement("script");
script.type = "text/javascript";
script.setAttribute("src", url);
head.appendChild(script);
head.removeChild(script);
Sorry for bad english...
Upvotes: 0
Views: 3947
Reputation: 3363
Changing an attribute by using it's name as a property doesn't work in all browswers afaik. So try to use:
script.setAttribute('type', "text/javascript");
instead of
script.type = "text/javascript";
Or if you don't mind using jQuery which handles for you the crossbrowser issues, do it like this:
$.getScript('yourscript.js');
Upvotes: 1