Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences in Internet Explorer and Firefox when dynamically loading content then going forward and back

I'm developing a web application where, due to slow database access, not all content in a page is loaded immediately but rather dynamically when the user clicks a button after optionally making a selection.

This works fine. However, after dynamically loading content, if I navigate to a different web page, then navigate back, in Internet Explorer the loaded content will have disappeared, i.e. the page will have reverted to the originally retrieved page. In Firefox (and Opera as well), however, the loaded content will still be there, i.e. the page will look like it did before I navigated away from it.

The Firefox behaviour is the desired behaviour in my case, as the user would routinely navigate to subpages and go back to the main page. My question is therefore, is there any way I can force Internet Explorer to exhibit this behaviour, or are there any possible workarounds to get the desired result?

like image 845
Knut Arne Vedaa Avatar asked Jan 14 '10 11:01

Knut Arne Vedaa


3 Answers

Here is my workaround solution for IE. It utilizes the fact that, even if the DOM is reset when navigating away and back to a page, input field values are still remembered.

For every dynamically loaded element, I also have a hidden input field where I "cache" the loaded value. I then have a function transferFromCache() which copies the values from each hidden input field to the corresponding element. This function is run at page init - which, in IE's case, is at page load AND every time one navigates back to the page.

This technique could probably be used to store the values of javascript variables as well.

like image 151
Knut Arne Vedaa Avatar answered Nov 15 '22 04:11

Knut Arne Vedaa


I don't think there's a method to get IE to emulate FF in this manner. The reason is to do with fairly fundamental aspects of the browsers. FF uses a mechanism for it's page history called 'Fast DOM caching' which (from my limited understanding) basically means that when it puts a page into the browser history then it will store the current DOM (so the current page state) in a serialised format, which means that when the page is reloaded from history the state is preserved and FF can do this much quicker as a lot of work is already done (parsing the HTML into a DOM, etc). In comparison, IE will simply store the HTML received initially as it's history file and will reload it when navigating history.

like image 41
workmad3 Avatar answered Nov 15 '22 05:11

workmad3


Here is an article about saving state in session variables, which may help

like image 23
Robert Avatar answered Nov 15 '22 04:11

Robert