Hey friends,

Have you ever tried out Google’s Image Search and opened a result window? You can see something like this one below:

Google Image Search Result

When you click on the image, you will be taken to the site, from where the picture was crawled, from the intermediate search page. But, when you try to go to the intermediate search page, you won’t be able to. If you haven’t tried it, try it!

This is because of Google, not linking it with a location.href, but with a location.replace. Enough of this! What is this location?

The window.location Object

Returns a Location object, which contains information about the URL of the document and provides methods for changing that URL. You can also assign to this property to load another URL.


var locationObj = window.location; window.location = newLocation;

locationObj is an object of type Location, providing information about the current URL and methods to change it. Its properties and methods are described below.
newLocation is a Location object or a string, specifying the URL to navigate to.

Whenever a property of the location object is modified, a document will be loaded using the URL as if window.location.assign() had been called with the modified URL.
Replace the current document with the one at the given URL:

function goToLink() {   window.location = "http://www.praveentech.net";} // in html: <button onclick="goToLink();">PraveenTech Research Labs</button>

location.replace(url) replaces the current document with the one at the provided URL. The difference from the assign() method is that after using replace(), the current page will not be saved in session history, meaning the user won’t be able to use the Back button to navigate to it.