Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$(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 stuff happens
});

Works perfectly fine in safari and chrome (I'm on mac osx 10.8), however doesn't seem to be working on firefox (19.0.2). Is there a fix or something that need's to be applied in order to make firefox work with it?

It works if I clear cache in firefox, but doesn't work any time after that.

like image 272
Ilja Avatar asked Mar 24 '23 09:03

Ilja


2 Answers

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
};
like image 157
hvaughan3 Avatar answered Apr 06 '23 01:04

hvaughan3


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

like image 23
jbduzan Avatar answered Apr 06 '23 01:04

jbduzan