PDA

View Full Version : OnLoad code is not executed (sometimes)



Luys
04-17-2012, 10:05 AM
Hi all!

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




<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:




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

jscheuer1
04-17-2012, 02:33 PM
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:


(function($){
$(window).load(function(){
setTimeout(function(){
WHATEVER
}, 1000);
});
})(jQuery);