Location.replace()

JavaScript 1.1+, JScript 3.0+ Nav3+, IE 4+, Opera3+ Syntax

location.replace(URL)

Description

The replace() method is used to load a new page, specified by URL, in the current browser window. The new page replaces the previous page's position in the history list.

Example

Listing 7.388 shows the replace() method being used to load the new Web site.

Listing 7.388 Example of the replace() Method
<html>
<head>
<title> Using the replace method of the Location object</title>
</head>
<body>

<form name="form1">
Click the button to load the new page: http://www.mcp.com
<br>
<br>
<input type="button" name="load" value="Load new page"
onClick='document.location.replace("http://www.mcp.com")'>
<br>
</form>

</body>
							 </html> ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.