Re: History Replacement And New Location Combined




"abc" <vpozek@xxxxxxx> wrote in message
news:1184097904.076494.222270@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have a set of web pages each containing a form with GET method. On
submit, I need to parse the form, add element values to the
location.search query, replace the current history location's URL with
the newly constructed one (updated form fields!), and THEN to invoke
the next page. Since each page would run restorePage() function on the
page load, each form would be restored on the browser's back button
request. Here's the brief overview of the logic:

<html>
<head>
<script>

savePage(){

// Parse the form and add parameters to the current location.search

a = location.search.substring(1);
for (i=0; i<form.length; i++){
a += '&' + form.elements[i].name + '=' + form.elements[i].value;
}

// Remember form fields' values
location.replace('currentpage.shtml?' + a);
// Pass them to the next page
setTimeout("document.location = 'nextpage.shtml?' + a;", 1000);
return false;
}

restorePage(){

// Parse the query and fill out the form

args = new Array();
pair = new Array();
a = location.search.substring(1);

args = a.split('&');

for (i=0; i<args.length; i++){

pair = args[i].split('=');
form.elements[i].value = pair[1];
}

</script>
</head>

<body onLoad="restorePage();">
<form method="get" action="javascipt: savePage();"
onSubmit="checkForm();">
:
:
</form>
</body>
</html>

As could be seen from the code above, I synchronize replace and load
requests, giving the replace request a full second to execute. But -

Not sure what you mean by "synchronize", but I think the location.replace
will stop your script dead in its tracks.

I have to admit, I can't figure out what you are trying to accomplish here.
But I can tell you that you don't want a form with a javascript action. Can
you post a link to a page that works without JS and how you are trying to
enhance the experience with JS?


.


Quantcast