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.
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
};
did you try window.onload = function(){}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With