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

MethodDescriptionMore Info
assign()Loads a new documentPreserves History
reload()Reloads the current document
replace()Replaces the current document with a new one (Loads a document)Replaces History

LEAVE A REPLY

Please enter your comment!
Please enter your name here