Friendly Page Redirect - DHTML Lab - DHTML Diner | 3 | WebReference

Friendly Page Redirect - DHTML Lab - DHTML Diner | 3

DHTML Diner Logo

Friendly Page Redirect

Replacing History Entries

Navigator 3.0 (yes, it was that long ago, but the method-in-question is still rarely used) introduced the replace() method of the location object. The syntax is:

window.location.replace(URL string)

The page represented by the URL string argument of the replace() method, will load into the browser window and replace the current page being viewed in the history stack.

Using replace(), the diagram from the previous page would look like this:


<A HREF="coolpage.html">
See this Cool Page!</A>


IE4 = document.all;
if (!IE4)
sorry.html replaces coolpage.html both in the browser window and the browser's history stack.

The history stack would therefore look like this:



Now, if we are viewing sorry.html and click the Back button, we will navigate to index.html, which we intuitively feel is the previous page we visited (even though it wasn't).

So, if you have Web pages that for some, or all, users simply load and redirect browsers to a new page, use the replace() method. For simple dynamic JavaScript navigation, without redirect, use the window.location= syntax.

Produced by Peter Belesis and

All Rights Reserved. Legal Notices.
Created: Mar 21, 2000
Revised: Mar 21, 2000