Two of the three javascript window location object methods seem to do the same thing.  They do not. The window location methods are assign(), reload(), and replace(). The reload() method does what you think. Both assign() and replace() appear to simply open a new page.

So…Uhhh….. What’s the difference between javascript location.assign() and location.replace()?

It has to do with your browsers history.

 

Difference between assign() and replace()

The “url” is whatever url you pass as an object for the javascript window location object method.

window.location.assign("url") causes a new document to load, while adding the current to the history.

window.location.replace("url") will replace the current document. It replaces the history in the browser so you can’t go back.

 

Javascript Window Location Object Methods

Method Description More Info
assign() Loads a new document Preserves History
reload() Reloads the current document
replace() Replaces the current document with a new one (Loads a document) Replaces History

 

Here are the javascript window location object properties.

http://www.w3schools.com/jsref/obj_location.asp

 

Search Terms:

Javascript Window Location Object Methods,  Window Location Methods, Javascript Window Methods

One thought on “Javascript Window Location Object Methods

  1. Pingback: Javascript Window Location Object Properties

Leave a reply

required

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">