4

I want to know what is the difference between location.replace() and location.assign().

I looked carefully but I didn't notice any difference between them!

Delan Azabani
  • 79,602
  • 28
  • 170
  • 210
Rasoul
  • 93
  • 1
  • 8
  • u should tag it javascript not asp.net – abhijit Aug 06 '11 at 08:02
  • Have a look at this question - http://stackoverflow.com/questions/4505798/difference-between-window-location-assign-and-window-location-replace – ipr101 Aug 06 '11 at 08:03
  • 1
    Nothing to do with `asp.net` and everything to do with `javascript`; re-assigning as such. Also rejected your edit for adding `asp.net` back to the tags; it has nothing to do with `asp.net`. – Delan Azabani Aug 06 '11 at 08:03

2 Answers2

6

location.replace() goes to the page with the argument, replacing the current page in history.

location.assign() goes to the page with the argument, adding a new item to the history.

https://developer.mozilla.org/en-US/docs/Web/API/Window/location

MrMythical
  • 8,908
  • 2
  • 17
  • 45
Delan Azabani
  • 79,602
  • 28
  • 170
  • 210
1

From MDN on replace():

Replace 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.

https://developer.mozilla.org/En/Window.location

Paul
  • 139,544
  • 27
  • 275
  • 264