#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    52
    Rep Power
    9

    Reload javascript on IE9


    Using IE9.

    In the JSP page, I added <script type="text/javascript" src="test/scripts/test.js" ></script>

    The file test.js contains a simple function test(){alert("loaded");} to open the alert window.

    Next I created a button named Launch to call this function. When clicked the button, just as expected, the popup window opened and displayed the word: loaded. So far so good.

    Then I went to the browser's URL address box on top and launched a new page, such as www.google.com. Once this page is loaded, I clicked the browser's BACK button to came back to my original page.

    Once my page was loaded, I clicked the Launch button. This time, the function test(){alert("loaded");} never got executed.

    When so?


    (It seems that when the BACK button brought back the original page, the <script type="text/javascript" src="test/scripts/test.js" ></script> is either not execute or the test/scripts/test.js is not loaded. However the same codes worked well on Firefox).
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,135
    Rep Power
    120
    Try this...

    [code=JavaScript]<script>
    function test()
    {
    alert("loaded");
    }
    document.onreadystatechange = function() {
    if (document.readyState=="complete") {
    new test();
    }
    }
    </script>[/code]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    52
    Rep Power
    9
    The problem is that the sample code I gave is quite simple. In reality, the javascripts are put in multiple .js files which are in turn loaded by a group of <script type="text/javascript" src="xxxxxxxx/yyy.js" ></script>. After came back to the previous page via the browser's BACK button, for some reason, the .js files are either not loaded or not interpreted by the browser. As the result, when clicked the same button as before, the same functions contained in the file גןdid not get executed.
    Last edited by otnj2ee; October 24th, 2012 at 08:41 PM.
  6. #4
  7. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,135
    Rep Power
    120
    Oh... sorry, missed the button; was thinking you needed a document event trigger. If your function has been assigned to the button (either dynamically or inline); the button's DOM event (ie "onclick") still should trigger the function; whether you remain on the page or leave the page and then, come back to the page. If the button has been assigned an DOM event; it should retain, that event. Unless your button's DOM event is re-assigned somewhere in your other JavaScript files.

IMN logo majestic logo threadwatch logo seochat tools logo