Safari testcase | load script dynamically

When creating a script-element with document.createElement and insering this element into the DOM, the attached script is not executed.

For non-IE, show-source to see comments in javascript for more info.

The to be loaded script.

document.createElement

function ()
//--#This test loads a script that shows an alert
//--#Works in Mozilla, IE failes.
{
  var script=document.createElement('script');
  var head=document.getElementsByTagName('head')[0];
  script.setAttribute('type','text/javascript');
  script.setAttribute('src','script.js');
  head.appendChild(script);
}
function ()
//--#This test loads a script that shows an alert (old school style)
//--#Works in IE, Mozilla
{
  var script=document.createElement('SCRIPT');
  var head=document.getElementsByTagName('HEAD')[0];
  script.language='javascript';
  script.src='script.js';
  script.defer='defer';
  head.appendChild(script);
}
function ()
//--#Insert it into the body
//--#Works in IE
{
  var script=document.createElement('script');
  var body=document.getElementsByTagName('body')[0];
  script.setAttribute('type','text/javascript');
  script.setAttribute('src','script.js');
  body.appendChild(script);
}


Back to the bugs