Browser "Back" fails after javascript redirect?

S

Simon Wigzell

I'm using :

window.location.href = [newUrl]

to redirect to a web page. From the new webpage, when you click the browser
"Back" button you of course end up on the same old page and get redirected
immediately to the new page. Apart from double clicking really fast (!) or
putting in a delay with the old "Your browser will be redirect in 5
seconds...blah blah blah" is there some other way of handling this? e.g. if
the first page could be aware that it has been reached with a "Back" button
and then perform a "Back" of it's own, then I'd be happy. Any other way of
handling this situation? Thanks!
 
L

Lee

Simon Wigzell said:
I'm using :

window.location.href = [newUrl]

to redirect to a web page. From the new webpage, when you click the browser
"Back" button you of course end up on the same old page and get redirected
immediately to the new page.

window.location.replace(newUrl);

will replace the current page with the new page in the
browser's history, so hitting BACK will take you to the
previous page, instead.
 
S

Simon Wigzell

Dohhhh! (Slapping forehead)

Talk about making a mountain out of a molehill! Thanks!



Lee said:
Simon Wigzell said:
I'm using :

window.location.href = [newUrl]

to redirect to a web page. From the new webpage, when you click the browser
"Back" button you of course end up on the same old page and get redirected
immediately to the new page.

window.location.replace(newUrl);

will replace the current page with the new page in the
browser's history, so hitting BACK will take you to the
previous page, instead.
 
L

Lasse Reichstein Nielsen

Simon Wigzell said:
I'm using :

window.location.href = [newUrl]

to redirect to a web page. From the new webpage, when you click the browser
"Back" button you of course end up on the same old page and get redirected
immediately to the new page. Apart from double clicking really fast (!) or
putting in a delay with the old "Your browser will be redirect in 5
seconds...blah blah blah" is there some other way of handling this?

location.replace([newUrl]);

This replaces the current page in the history instead of just pushing
the new page. The redirect page is no longer there to go back to.

/L
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top