[thelist] Javascript Redirect

James Aylard evolt at equilon-mrc.com
Thu Apr 5 11:56:00 CDT 2001


> Could someone tell me how to use a javascript location redirect that
> the user to back out of the website they were redirected to, without being
> redirected right back in over and over.

    Yes. Try this:

<script language="javascript1.1">
    window.location.replace("newPage.html") ;
  // -->
<script language="javascript">
    window.location.href = "newPage.html" ;
  // -->

    The replace() method was introduced in Javascript 1.1, so to avoid
errors in browsers capable of only Javascript 1.0 (primarily Netscape 2 and
IE 3), you set the language attribute in the first script block to
"javascript1.1". Because the replace() method replaces the current page in
the browser's history with the targeted page, users will suffer no redirect
loop when they click on the Back button.
    The href property in the second script block will not prevent a redirect
loop, so is far less desirable. You could help minimize this effect by
setting a delay on the href redirect, like so:


    With a two-second delay, a user could still click the Back button
without getting caught in a loop.

James Aylard

More information about the thelist mailing list