...

View Full Version : IE vs Firefax Back Button Reload



mikeb539
12-19-2011, 08:44 PM
Sorry if this is the wrong place for this question, but...

I'm having an issue with the difference in behavior between the IE and FF back buttons. I'm using jQuery to create collapsable div regions which contain text boxes on a search form. After submit, if the use clicks the back button in FF, the region(s) the user had previously expanded, show as expanded. Also, there search term is still present. In IE, when clicking the back button, all regions are collapsed, in there original loaded state, but the search term is still saved.

I put the following code at the top of the page:

onload=function(){
alert('Onload!');
}

When clicking the back button in FF, nothing happens. For IE, the alert pops up. This tells me that IE reloads the page (but somehow still saves some things, like the search text).

My question is, is there a way to keep IE from reloading when the use clicks 'back'? I will be creating my own 'edit' back button for users to get around this, but I also would like to prevent this from confusing users and causing undesired results.

Any help would be greatly appreciated.

chump2877
12-20-2011, 03:47 AM
My question is, is there a way to keep IE from reloading when the use clicks 'back'?

Not to my knowledge. You can't change the default behavior of the browser's forward and back buttons.

Instead, you could use a cookie here to save the state of the collapsable divs and the values of the text boxes inside your divs (on submit of your form). So, when you hit the back button in the browser, if the page reloads, then an onload event handler checks for something in the cookie. If the event handler finds something in the cookie, then those values are used to restore the page to its previous state.

At some point, if you are using a cookie like this, you would need to delete the data in the cookie -- perhaps in the onunload event of the second page (exactly how you do this will depend on the flow and interface of your web application). This will prevent old values in the cookie from restoring previous states of the form whenever the page loads (aside from when a user hits the browser's back button to arrive there).

mikeb539
12-20-2011, 04:04 PM
Thanks for the suggestion...I was just thinking of something similar to that after work. I'll try it out.

chump2877
12-20-2011, 04:10 PM
Another idea -- if you want to use HTML5 for your project -- is to try the new web storage objects (http://www.w3schools.com/html5/html5_webstorage.asp). Another link here (http://coding.smashingmagazine.com/2010/10/11/local-storage-and-how-to-use-it/). But you have to assume that this will only work for the very latest versions of browsers. If that isn't a limitation for you, then the new objects are easier to use than cookies, and they can store more data.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum