spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / dhtml / diner / redirect
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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:

index.html

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

coolpage.html

<SCRIPT>
IE4 = document.all;
if (!IE4)
window.location.replace("sorry.html");
</SCRIPT>
sorry.html replaces coolpage.html both in the browser window and the browser's history stack.

The history stack would therefore look like this:

1.sorry.html
2.index.html
  ^
|
v

sorry.html

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

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

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

URL: http://www.webreference.com/dhtml/diner/redirect/3.html