Why document.write creates a new entry in browser history (how to avoid it)?

T

Trastabuga

On the current page the user is at I need to write something like
"Please, wait" (I am using document.write for this) and then open a
new url with some lengthy calculation process so the page will load in
a few seconds.
The <body onload="redirect()"> doesn't work for me in this case, so I
thought that if I update current page with new text no harm would be
done. It works, but now the user will have a new page in the history
with the same url as previous but different contents ("Please, wait"
paragraph). I thought that browser keeps history based on new URLs,
but looks like it's not true. How can I overwrite the content of a
page without causing a new entry in the browser history?

Thank you,
Andrew
 
A

ASM

Trastabuga a écrit :
On the current page the user is at I need to write something like
"Please, wait" (I am using document.write for this) and then open a
new url with some lengthy calculation process so the page will load in
a few seconds.
The <body onload="redirect()"> doesn't work for me in this case, so I
thought that if I update current page with new text no harm would be
done. It works, but now the user will have a new page in the history
with the same url as previous but different contents ("Please, wait"
paragraph). I thought that browser keeps history based on new URLs,
but looks like it's not true. How can I overwrite the content of a
page without causing a new entry in the browser history?

function wait() {
var wait = document.createElement('H1');
wait.style.textAlign = 'center';
wait.style.color = 'red';
wait.style.background = '#ddd";
wait.style.width = '100%';
wait.style.position = 'absolute';
wait.style.top = '50px';
wait.innerHTML = 'Please Wait'
document.body.appendChild(wait);
}

insteed of :
document.body.appendChild(wait);
you can have :
document.getElementById('someWhere').appendChild(wait);
if you want your message in div 'someWhere'
and if this div is positioned
 
A

ASM

Randy Webb a écrit :
ASM said the following on 3/26/2007 7:28 PM:

Are you sure that the name of a function being the name of a variable is
a good idea?

Ooops !
I though I did correct : function waiter() { ... }
before to post :-(
 
A

ASM

Randy Webb a écrit :
ASM said the following on 3/26/2007 7:28 PM:

Are you sure that the name of a function being the name of a variable is
a good idea?

Not too much,
but as the variable 'wait' doesn't go away form function 'wait',
here it is OK.

Test with some correction(s) of typo :

<html>
<script type="text/javascript">
function wait() {
var wait = document.createElement('H1');
wait.style.textAlign = 'center';
wait.style.color = 'red';
wait.style.background = '#ddd';
wait.style.width = '100%';
wait.style.position = 'absolute';
wait.style.top = '50px';
wait.innerHTML = 'Please Wait'
document.body.appendChild(wait);
}
wait();
</script>
</html>
 

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

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top