Email conversation
From | Christopher R Newman |
To | Me |
Subject | Q about cacheing dynamically created HTML nodes |
Date | 14 September 2006 21:58 |
Hello Mark,
Few people would know the answer to this question so I'm hoping you'll
randomly select to answer this email. :)
Well, I'm using the DOM to allow users to dynamically create additional text
fields in a form. Thanks to your site (which is nice, by the way) I can do
it 2 different ways that work in both IE and Mozilla-based browsers.
Problem is: if the page is refreshed or they go to the next page and then
back, the input elements that were created disappear. I'd expect IE to
forget everything, but Firefox always seemed to cache every little detail
when returning to previous pages.
Do you know if that is expected and, if so, is there a way to keep the
created nodes? Even if you just point me in the right direction, that would
help. Thanks in advance.
Chris
From | Me |
To | Christopher R Newman |
Subject | Re: Q about cacheing dynamically created HTML nodes |
Date | 15 September 2006 10:11 |
Chris,
> I can do it 2 different ways that work in both IE and Mozilla-based
> browsers.
http://www.howtocreate.co.uk/sendEmail.php#testbrowsers
Please follow my guidelines if you intend to contact me in future. (There
are more than 2 browsers in this world, and this is not 1997.)
> Problem is: if the page is refreshed or they go to the next page and then
> back, the input elements that were created disappear. I'd expect IE to
> forget everything, but Firefox always seemed to cache every little detail
> when returning to previous pages.
Several browsers, including Opera, Firefox, Safari, and IE Mac use fast
history navigation; where the DOM of the page is maintained when you go back
or forward. IE Windows supposedly has something similar, but in general it
doesn't work (it fails on even my simplest tests).
[Ed. note that fast history navigation is suggested (but not well defined)
in RFC 2616 (HTTP/1.1) section 13.13]
Konqueror and iCab do not use fast history navigation at all.
Firefox recently added the capability - in version 1.5 I think. However,
Firefox's version is quite limited compared with the other browsers. Firefox
will normally remember only 3 pages worth of DOM information. The others
will remember as many as they can before they reach a predetermined memory
limit (on my computer that can mean around 100 pages or more with Opera), at
which point they stop trying to remember. In Opera and Firefox, the user can
also disable it, but very few do.
All browsers will use several triggers to decide if a page must _not_ have
its DOM remembered, such as if it performs certain actions in an onunload
event listener, or communicates with a parent frame during page loading.
They will also disable it on secure sites if the page sends headers saying
not to cache it.
In other words, there are times when what you are hoping will happen, will
not happen in any browser. From the looks of things, it will never happen in
IE Win. You cannot rely on it.
So you will need to emulate it yourself if you want it to happen in any
browser where it does not work on its own. Onunload, store a cookie that
remembers the current setup. Then onload, recreate it, if the cookie exists.
If the browser uses fast history navigation, onload will not fire, so you
will not end up accidentally duplicating content.
Note that using onunload will cause Firefox, Safari, and IE Mac to disable
fast history navigation, whereas in Opera it will not disable it unless you
do something damaging, such as disabling a form input. So you may want to
store the cookie incrementally, each time you change something, and not
onunload. This will allow Firefox, Safari, and IE Mac to use fast history
navigation if they want to.
Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
From | Christopher R Newman |
To | Me |
Subject | Re: Q about cacheing dynamically created HTML nodes |
Date | 15 September 2006 15:29 |
Mark,
This is an internal website so I know my users are limited to IE and
Netscape/Firefox. Sorry to offend you for not using Opera. :)
The information was VERY helpful. If you still maintain your website, I
think you should post it. Even if you just copy/past this email, it would
be good. This sort of stuff isn't easily found on the net.
I thought about doing the cookie thing, but didn't know about the
onload/unload stopping fast history navigation in some browsers. Of course,
I need IE to work so it doesn't matter. Maybe I'll try the incremental
cookie approach.
I appreciate your help. If you ever have any TCL, Perl CGI, VBScript, or
Japanese questions, let me know so I can try to return the favor.
Thanks,
Chris
From | Me |
To | Christopher R Newman |
Subject | Re: Q about cacheing dynamically created HTML nodes |
Date | 15 September 2006 16:45 |
Chris,
> The information was VERY helpful. If you still maintain your website, I
> think you should post it. Even if you just copy/past this email, it would
> be good. This sort of stuff isn't easily found on the net.
http://www.howtocreate.co.uk/emails/ChristopherRNewman.html
Maybe someday I will turn it into a proper article, since I agree, it is not
easy to find useful info. The only one I know that actually says anything
really useful from a developer point of view is Opera's, as it shows how you
can force either behaviour in Opera:
http://www.opera.com/support/search/supsearch.dml?index=827
The only info I have found on Mozilla says how to change the number of pages
it works for, and how it will choose the default. That is only of use to a
user, not an author.