javascript redirect + back button

Associate
Joined
20 Mar 2006
Posts
692
Hi,

quick one -

if as a redirect you use setTimeout with window.top.location.href=...

this means if you've gone through the landing/redirect page to get where you are going and hit back you just end up back on that page and the timeout is one second so you have to time clicking back again quite well :P if you don't want to end up back where you started.

Is there any reason anyone can think of why you wouldn't use window.replace instead of window.location.href=

I want to suggest it but I don't want to look silly, I'm not really a programmer or scripter but this redirect has bugged me a couple of times. Only things that immediately spring to mind is IE supporting this incorrectly (only tested my solution in firebug/firefox), a reasonable design/functionality decision (the redirect page is also the logout page as well as the first page you get to when you navigate to the app via a certain way). Am expecting there is some glaringly obvious reason why you wouldn't do this and they'd be all patronising when I suggest it :P
 
anything specific on that page you are referring to that I may have missed? I was looking for any reason not to use replace, be it functional or technical...
 
I don't know if I'm looking at the right thing, I really do web stuff.

The difference between location.href and location.replace is that the former will create a new history entry on the visitors computer. This means that if they hit the back button, they can get stuck in a 'redirection loop'. This is usually undesirable and may have unwanted side effects - most pay per click search engines will not allow the submission of URLs that 'break' the back button.
 
Yeah, window.location.replace = 'xyz.com' is the answer.

It replaces the page doing the redirect in the browser history, so if the back button is pressed, you go to the originating page, not the redirecting page.
 
Back
Top Bottom