By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,900 Members | 1,078 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

Browser Quirk: onload/onunload do not fire on back/forward/refresh (Opera)

Expert Mod 15k+
P: 16,027
onload and onunload events do not fire when going back, forward or refreshing the page


Any code using onload or onunload, e.g.
Expand|Select|Wrap|Line Numbers
  1. window.onload = init;
where init() is a function which initialises some variables (for example).

There is no solution because according to Opera developers and users this is not a bug. Opera maintains the runstate of scripts, so it's as if we never left the page when we return back to it. According to Opera, onload should only fire when loading the page for the first time and onunload should fire when unloading the page completely, not when just leaving the page by pressing the back, forward or refresh button. Refresh is considered to be a reload, not an unload.

This should be something you should be mindful of when depending on onload and onunload in your code.

Obviously, if onunload does not fire, onbeforeunload (which is a non-standard event supported by some browsers) will not work either.

More Bugs, Quirks and Inconsistencies
Aug 18 '07 #1
Share this Article
Share on Google+