document.GetElementByID IEplorer

Discussion in 'JavaScript' started by nocuser, Jun 3, 2010.

  1. #1
    Hi people, the following code is not working for IExplorer.
    Could you help me?

    <script id=url language=javascript ></script>
    <script type="text/javascript">document.getElementById("url").src = "http://localhost/aro.aspx?&key=C763&refnum=yY9&location=" + document.location;</script>
     
    nocuser, Jun 3, 2010 IP
  2. makechapman

    makechapman Greenhorn

    Messages:
    80
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    document.getElementById is DOM...
    <script> is not DOM..
     
    makechapman, Jun 14, 2010 IP
  3. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #3
    stephan2307, Jun 14, 2010 IP
  4. Pudge1

    Pudge1 Well-Known Member

    Messages:
    912
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    Digital Goods:
    1
    #4
    Actually that works with JavaScript too
     
    Pudge1, Jun 14, 2010 IP
  5. netload

    netload Member

    Messages:
    105
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #5
    Some browsers don't work with document.getElementById. This is universal function for all browsers:

    function getElement(id)
    {
    	var itm = null;
    	if (document.getElementById) {
    		itm = document.getElementById(id);
    	} else if (document.all){
    		itm = document.all[id];
    	} else if (document.layers){
    		itm = document.layers[id];
    	}
        return itm;
    }
    
    var node = getElement("url")
    if (node) {
    	node.src = ...
    }
    
    Code (markup):
     
    netload, Jun 15, 2010 IP
  6. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #6
    try checking if you can actually access the script like this:

    var e = document.getElementById("url");
    alert(e);

    if the alert gives you a script object, then you're fine. if it's undefined, you know this won't work.
     
    NoamBarz, Jun 16, 2010 IP
  7. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #7
    google 'lazyloading javascript'. what you are doing is correct - have a look at http://ajaxpatterns.org/On-Demand_Javascript

    the favoured lazyload method is
    <script>
        document.write('<script src="', 'http://cross.domain.com/other.js', '" type="text/javascript"><\/script>');
    </script>
    
    Code (javascript):
    - most compatible and non-blocking, i suppose.
     
    dimitar christoff, Jun 16, 2010 IP