www.webdeveloper.com
Results 1 to 5 of 5

Thread: multiple body onload function

  1. #1
    Join Date
    Nov 2008
    Posts
    1

    Post multiple body onload function

    Dear All,

    I have 3-4 jsp pages each have there own body tags which consists of onload function.
    My problem is if i includes all jsp pages into one jsp page then all body onload functions not working. please let me know how to overcome this problem.

    Thanks you peoples
    waiting 4 quick response

  2. #2
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    <script type="text/javascript">
    function start() {
    // put all your onload functions here
    }
    window.onload = start;
    >/script>

    Then you don't need anything in the <body> tag.

  3. #3
    Join Date
    Apr 2006
    Location
    Houston
    Posts
    1,374
    A somewhat more generic approach I take is to include this function in every page via a src=blahblah.js assignment (usually just included in a js file along with all my other utility type of functions)

    Code:
    //////////////////////////////////////////////////////////////////////////////
    // addLoadEvent
    //
    //		Add a new function to the windows onload event without 
    //		removing any previous existing functions.
    //
    //  @param   func - function name to add to windows.onload    
    //  @return  void
    //////////////////////////////////////////////////////////////////////////////
    function addLoadEvent(func) {
    	
    	// Save current onload functions
    	var oldonload = window.onload;
    	
    	// If this is the first function then assign it to window.onload
    	// else assign it along with the current functions 
    	if (typeof window.onload != 'function') {
    		window.onload = func;
    	}
    	else {
    		window.onload = function() {
    			oldonload();
    			func();
    		};
    	}
    }
    On each individual page you can add new functions to the body onload event by executing

    addLoadEvent(somefunctionname1);
    addLoadEvent(somefunctionname2);
    .
    .
    .
    etc..

    in the the head of each page.

  4. #4
    Join Date
    Nov 2008
    Posts
    7
    You can do this:
    Code:
    ...
    <body onload="function1();function2();function3();">
    ...
    </body>

  5. #5
    Join Date
    Apr 2012
    Posts
    1

    Thanks

    Thanks stephen

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Posting Permissions

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



Recent Articles