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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

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

    Problem
    onload and onunload events do not fire when going back, forward or refreshing the page

    Browser
    Opera

    Example
    Any code using onload or onunload, e.g.
    [CODE=javascript]window.onload = init;[/CODE] where init() is a function which initialises some variables (for example).

    Solution
    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
Working...