Browsers behave differently after modifying document

C

Clive Backham

I'm trying to dynamically modify the contents of a form (adding new
input fields in response to user actions). After the fields are added
and the form submitted, if the user then presses the Back button to
return to the form, the dynamically added fields may or may not be
present depending on the browser. Firefox 2.0.0.12 and Opera 9.10 keep
the fields, but IE 6.0 and Safari 3.0 lose them. I would like the
fields to be kept. I'm wondering if there is some action I'm failing
to perform after adding the extra field that is required to make the
change to the document persistent.

Here's a simplified version of the page:

<html>
<head>
<script type="text/javascript">
var counter=0;
function newfield()
{
counter++;
var xinp = document.createElement("input");
xinp.name = "newinput" + counter;
document.getElementById("sp1").appendChild(xinp);

// SHOULD I BE DOING SOMETHING ELSE HERE
// TO MAKE THE NEW FIELD SURVIVE A
// SUBMIT/BACK CYCLE?

}
</script>
</head>
<body>
<form action=test.jsp>
<input type=button value="add field" onclick="newfield()" />
<span id=sp1>
</span>
<input type=submit>
</form>
</body>
</html>
 
H

Henry

I'm trying to dynamically modify the contents of a
form (adding new input fields in response to user actions).
After the fields are added and the form submitted, if the
user then presses the Back button to return to the form,
the dynamically added fields may or may not be present
depending on the browser. Firefox 2.0.0.12 and Opera 9.10
keep the fields, but IE 6.0 and Safari 3.0 lose them.

Some browsers keep recently visited pages in memory when you move on
to a different page. This means that when you go 'back' to such a page
you get to see it quicker and it is in exactly the state it was left
in (with the exception of running timers in some cases, which may have
been stopped and not be re-started). Other browser will re-load the
page from the (possibly cached) original HTML. In the latter case
dynamic modification made during a previous visit will not survive.
And the browsers that do keep pages in memory will not do so for ever,
so eventually they will be pushed out of memory and so going that far
back will still require a re-load from the HTML source.
I would like the fields to be kept.

Maybe, but that is not going to happen on the client.
I'm wondering if there is some action I'm failing
to perform after adding the extra field that is
required to make the change to the document persistent.
<snip>

There is nothing that you can do. You can, to some degree, achieve
consistent behaviour by providing the pages with - onload - and/or -
onunload - handlers, as they seem to inhibit a browser's ability to
keep a page in memory after you navigate away form it, but that
consistent behaviour is having the page load without the added fields
if the 'back' button is used.
 
C

Clive Backham

There is nothing that you can do. You can, to some degree, achieve
consistent behaviour by providing the pages with - onload - and/or -
onunload - handlers, as they seem to inhibit a browser's ability to
keep a page in memory after you navigate away form it, but that
consistent behaviour is having the page load without the added fields
if the 'back' button is used.

OK, thanks for the info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,144
Messages
2,570,823
Members
47,369
Latest member
FTMZ

Latest Threads

Top