How to call Onload() on pressing browser back button Wednesday, May 6, 2009

Lets say there was a scenario where you have a registration process which has sevaral pages. And you want to expire a page if the user clicks the browsers back button in the middle of the registration process. This issue came because firefox saved webpage data in its browser cache. So whenever the user hits the back button, data will be loaded from the browser cache instead of getting it directly from the server-side.


I saw in a lot of places where people have suggested to use metadata tags to tell the browser to disable html caching. most often use matatags are displayed below.


META HTTP-EQUIV="Pragma" CONTENT="no-cache">
META HTTP-EQUIV="Expires" CONTENT="-1">

but non of these worked for firefox. I can tell you that for IE6 and IE7 the above tags works fine.

Seaching the net for hours, i finally found a solution. Its calling the javascript unload() function in everypage where i want to call OnLoad() when i click back button.

The javaScript code to use is:
window.onunload = function dummy(){};

And i used browser cookies validate the page expiration.
You can see a complete demonstration by downloading the file below:



0 comments: