Skip to content Skip to sidebar Skip to footer

$(window).load Doesn't Seem To Be Working In Firefox

So I've got some code that need's to be executed only when content of the website is loaded so I place it within window load, like this: $(window).load(function() { //some stuf

Solution 1:

Incase anyone else find this page from Google...

For me the following does work on Firefox:

$(window).load(function() {
    //Do something
});

But when the page gets cached, such as when the back button is clicked, $(window).load() does not get called again. See this for the bug report. This is expected behavior from Firefox so do not expect a fix.

2 things to fix this are either stop the browser from caching the page when hitting the back button using this code (in addition to your $(window).load() code):

window.onunload = function(){}; //This forces bfcache to not cache the page

Or use the other jQuery event instead of $(window).load():

window.onpageshow = function () {
    //Do something
};

Solution 2:

did you try window.onload = function(){}


Solution 3:

In case you use jQuery. Use the jQuery event:

$(document).ready(function(){
    // YOUR CODE
});

Solution 4:

just simply do

my_function(){
    // some code
}

window.onload = my_function


Solution 5:

try this. it's working in all browser.

<script type="text/javascript">
window.onload=function(){
    alert('do something');  
}
</script>

Post a Comment for "$(window).load Doesn't Seem To Be Working In Firefox"