Is there any event which calls a javascript function as soon as the page/form loads ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jaya26
    New Member
    • Mar 2014
    • 3

    Is there any event which calls a javascript function as soon as the page/form loads ?

    I have a function written in js. I need to call this as soon aspage is finished loading. Now i am displacing this on mousehover event. I dont want to call this event, i want to see this change as soon as page is finished loading. Onload() doesnt work for me. i am using ie8.


    Code:
    <!DOCTYPE html>
    <html>
    <body>
    <head>
    <style>
    #blank_bar{
         width: 100px;
         height: 15px;
         background:grey;
    }
    
    #filled_bar{
         height: 15px;
         background:green;
    }</style>
    		
    <script>
    	function load()
    	{
    		var elem = document.getElementById('filled_bar');
    		elem.style.width=$countDetails + "%";
    	}
    </script>
    
    <p><b>Estimate Completion:&nbsp $countDetails% complete</b></p>
    
    <div id="blank_bar"><div id="filled_bar" onmouseover="load()"></div></div>
    
    
    </div>
    </body>
    </html>
    $countDetails is a computed value.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    Code:
    <body onload="load()">
    According to some info*) the function is executed after loading the 'body'
    *) 1 oreilly
    2 stackoverflow
    Last edited by Luuk; Mar 14 '14, 01:44 PM. Reason: links....

    Comment

    • jaya26
      New Member
      • Mar 2014
      • 3

      #3
      This doesnot work in IE but works in other browser. i tried this is IE8 but it doesnt work.

      Comment

      • Luuk
        Recognized Expert Top Contributor
        • Mar 2012
        • 1043

        #4
        "it does not work" ==> makes me laugh.... ;-(

        If next code works in IE6, i would not know why it should not work in IE8*
        Code:
        <html>
        <head>
        <script>
        function load() {
           alert('test');
          var elem = document.getElementById('test');
          elem.innerHTML="test";
        }
        </script>
        </head>
        <body onload="load()">
        <div id="test"></div>
        </body>
        </html>
        *sorry, i don't have a machine with IE8 here....
        Last edited by Luuk; Mar 22 '14, 09:25 AM. Reason: comment about that i dont have IE8

        Comment

        Working...