Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Redirect javascript

Frustration setting in. I picked up the javascript below from somewhere. It is supposed to be a proper redirect. I find, however, that won't allow the back button to work. Any guru-type input greatly appreciated. Bottom line: what's the best way to redirect from CD to an outside file?

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
window.location="subway/page1.htm";
// End -->
</script>
<noscript>
You should be redirected automatically. If not, click <a href="newfolder/page1.htm">here</a>.
</noscript>

Amos
Wednesday, February 19, 2003

I think this will be a problem with whatever re-direct you do. See, the previous page you were on is the redirect page, so when you go back, it automatically fowards you to the next page.

Maybe a javascript that invokes history -2 (or something like that, I don't know the syntax) might work for you.

www.marktaw.com
Thursday, February 20, 2003

You could also open the new page in a new window with target="_blank" in the href tag. A little clumsy perhaps, but this way people would know, that they were redirected.

Jorgen Brenting
Thursday, February 20, 2003

Its better to do this from the server side.

joel Goldstick
Thursday, February 20, 2003

Here's one way to do a redirect (though the best way is to configure the web server to do it).

<HTML>
<HEAD>
<META http-equiv="refresh" content="10;URL=http://newdomain.com">
<TITLE>The page you were attempting to access no longer exists!</TITLE>
</HEAD>

<BODY>
The page you were attempting to access no longer exists. <br>
<a href="/">Click here to go to the <i>newdomain.dom</i> if you are not automagically taken there within 10 seconds.
</BODY>
</HTML>

David Burch
Thursday, February 20, 2003

I was thinking of posting the Meta Refresh, but thought better of it.

But now that David posted it, I realized that this is a good alternative - the 10 seconds it takes for the page to change over will give whoever hits the back button ample time to hit it again.

www.marktaw.com
Thursday, February 20, 2003

A 10 second wait will also look good to the search engines. They do not like zero seconds redirect and might take you for a bad guy if you are too fast on the trigger (no similarities intended).

Jorgen Brenting
Friday, February 21, 2003

Thanks for the script!  I was looking for something this simple for a while. I was useing .js files before to do the same thing....

Thankful
Friday, January 30, 2004

*  Recent Topics

*  Fog Creek Home