Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Internet Explorer IE reloading bugs for dynamically loading JS files

    I am using the good article on updating the DOM to include external javascript files dynamically into the head of a page to load in prototype.js from the google servers. I can get it to work consistently in firefox, and it works in IE if I visit the page from somewhere else, or enter the URL into the address bar and hit enter. However if I force a refresh (ctl F5 or F5) it throws a javascript error stating:
    Code:
    Line: 4027
    char: 5
    Error: 'null' is null or not an object
    Code: 0
    This error is triggered at the
    Code:
    headTag.appendChild(scriptTag);
    line. Full code included below.

    Code:
    var protoUrl = "ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js"
    
    var protoHost = (("https:" == document.location.protocol) ? "https://" : "http://");
    
    //This function is used to include javascript files into the head section of the page
    function includeJavascript(src) {
      //Checks if the function includes the correct syntax to include js files
      if (document.createElement && document.getElementsByTagName) {
        var headTag = document.getElementsByTagName("head")[0];
        var scriptTag = document.createElement('script');
        scriptTag.setAttribute('type', 'text/javascript');
        scriptTag.setAttribute('src', src);
        headTag.appendChild(scriptTag);
      }
    }
    
    //include javascript src file
    includeJavascript(protoHost + protoUrl);

    I am using IE 7.0.5730.13

    Thanks a lot.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,524
    Thanks
    3
    Thanked 508 Times in 495 Posts
    test with same version of IE and works for me

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    var protoUrl = "ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js"
    
    var protoHost = (("https:" == document.location.protocol) ? "https://" : "http://");
    function includeJavascript(src) {
      //Checks if the function includes the correct syntax to include js files
      if (document.createElement && document.getElementsByTagName) {
        var headTag = document.getElementsByTagName("head")[0];
        var scriptTag = document.createElement('script');
        scriptTag.setAttribute('type', 'text/javascript');
        scriptTag.setAttribute('src', src);
        headTag.appendChild(scriptTag);
    alert(headTag.getElementsByTagName('SCRIPT').length)
      }
    }
    
    /*]]>*/
    </script></head>
    
    <body onload="includeJavascript('protoHost + protoUrl');" >
    
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post
    I am trying to run the includeJavascript function before the onload event to ensure that the prototype library is fully loaded before any other code is run. (i.e. AJAX requests in an onload function.)
    I put all of that code in an external javascript file, which includes the includeJavascript function call.

    any further help would be greatfully received.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •