Document.getElementByID and IE

HI people, the following code is not working for IE.
Could you help me, please?

<script id=url language=javascript ></script>
<script type=“text/javascript”>document.getElementById(“url”).src = “http://localhost/aref.aspx?&key=C763&refnum=yY9&location=” + location;</script>

It is done so as an example. You know…show how to use the function?

Why add a script when you’ve already got one that’s usable?
You don’t need to bother loading jQuery. It’s not needed in this instance. The changeScript function will work. Works on all my browsers, my friends Nokia 5800, all iPhones that have tested it :slight_smile:

BTW, you don’t need the extra script anymore, you can use the existing one provided you have finished with it

also, you can’t use


as it will not load src1.js (just found that out, trying to minimize the number of file being used)
changeScript(“src2.js”) can however be put in src1.js, and both will be called

This will work, even though the script you’re changing is the one you’re using :slight_smile:

<script type="text/javascript">
function changeScript(livescript_equation) {
var newEl=document.createElement('script');
newEl.setAttribute('type', 'text/javascript');

Unlike CSS stylesheet changers, the javascript will be kept in memory, so you can keep using this method to build layers of scripting. Look in to cache headers and expiry dates as well, really useful when using this type of script

Try this:

function addScript ( uri, callback )
  var script = document.createElement( "script" );
      script.src = uri;
  // Callback for when the script fully loads.
  if ( typeof callback === "function" ) {
    script.onload = script.onreadystatechange = function () {
      if ( !( r = this.readyState ) || r === "loaded" || r === "complete" )
        callback( uri );

  document.documentElement.childNodes[0].appendChild( script );

addScript( "",
  function () { alert( jQuery.fn.jquery ); }

Thanks, but I need that the script, which is returned by my aspx, is in some place of the body… not head…

I suggest you try this:

var hh = document.getElementsByTagName(‘head’)[0];



<script type="text/javascript">

var h = document.getElementsByTagName('head')[0];

var s = document.createElement('script');








var n="The Time Through Ages. In the Name of Allah, Most Gracious, Most Merciful. 1. By the Time, 2. Verily Man is in loss, 3. Except such as have Faith, and do righteous deeds, and (join together) in the mutual enjoining of Truth, and of Patience and Constancy.";


Hi, this code is creating the script element dynamically, but it doesn’t work for IE…

<script name="t1">
<script type='text/javascript'>
var ss = document.createElement('script');
var scr = 'http://localhost/aref.aspx?&key=634&ref=xGa&location=' + document.location;
ss.src = scr;
var hh = document.getElementsByName('t1')[0];

Any ideas?

Thanks, but it doesn’t work for IE…

I’m assuming the variable “location” is defined elsewhere.

Btw your original markup is kind of a mess (no offense.) You should always wrap attribute values in double quotes whenever possible.

Anyway, see if that works.

<script id="url" type="text/javascript" src=""></script>
<script type="text/javascript">
var scriptTag = document.getElementById("url");
scriptTag.setAttribute("src","http://localhost/aref.aspx?&key=C763&refnum=yY9&location="+ location);

Create the script element, do not use an existing one.