Hira Singh
Hira Singh

Reputation: 155

Script is not working in safari

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

Answers (1)

Mario A
Mario A

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

Related Questions