Results 1 to 2 of 2

Thread: OnLoad code is not executed (sometimes)

  1. #1
    Join Date
    Jan 2011
    Posts
    51
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default OnLoad code is not executed (sometimes)

    Hi all!

    This is the code I use till now for calling to a certain function on window load:

    Code:
    <script type="text/javascript">
    (function($){
    	$(window).load(function(){
    		
            WHATEVER
    
    	});
    })(jQuery);
    </script>

    Recently I changed the layout of the web page and there is a 'conflict' when the content try to adjust to the device (notebook, ipad, phone...): only a few times is activated the above function "on load".
    I think a setTimeOut like the following would solve the simultaneity of two actions:

    Code:
    setTimeout(function(){
    	WHATEVER2
    	})
    }, 1000)
    The question:

    What would then be the best way to combine the latter with the first code above?

    Thanks in advance for your answer.

    Luys

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Doing that, though it may or may not work some, might not be effective in all cases. And/or there might be a better way, one not involving a 1 second delay, maybe not even a timeout, maybe not even the window's load event.

    That said, to answer the question:

    Code:
    (function($){
    	$(window).load(function(){
    		setTimeout(function(){
    			WHATEVER
    		}, 1000);
    	});
    })(jQuery);
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Luys (05-04-2012)

Bookmarks

Posting Permissions

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