Adding an (even empty) unload event to your page ensures that most browsers automatically re-request the page when a visitor returns via the back-button. Unfortunately, Opera will still “reload” the page from its own cache. Try Demo without Fix (opens in new tab).
When might you want to reload from server? Example, you use the unload event to “kill” the server session on page exit (see why sessions should be closed soonest). If a user later “back-buttons” to your page, most browsers will re-request the page (starting a new session). Opera loads the page from cache – result no server session and your page’s form will not work (the user would have to know to manually refresh the page).
From Googling, and testing, the addition of cache control headers etc don’t force Opera to reload from server either.
It worked fine in my tests; compare the Before Demo and After Fix Demos (both open in new tabs). However, I do not guarantee the code below is complete, or covers all possibilities and circumstances.
window.name = new Date().getTime(); // makes name unique
Where should I place this line:
ideally in one of your event handler functions that will always be executed* in circumstances where you need it. I use the onclick or unload event to kill the server session when a visitor exits via a link . So I can simply add the above line to this function.
* Opera only fires the unload event on page exit via a link.
Notes on the Code:
It works for me with Opera (12.14) using pages with <!DOCTYPE html>; and I’ve no reason to believe it wont work for other versions of Opera and othe document types, but obviously I can’t guaranttee it will work in all circumstances.
Feel free to use the comments to let me know whether or not it works with other versions of Opera; or to critique the code, or to suggest alternative solutions.
Author: Andy W+
Leave a Reply