What's the difference between window.location.assign(url)
and window.open(url, '_self')
?
Related questions:
- Difference between window.location.assign() and window.location.replace()
- What's the difference between window.open(url) and window.location.href = url on Firefox?
What's the difference between window.location.assign(url)
and window.open(url, '_self')
?
Related questions:
- Difference between window.location.assign() and window.location.replace()
- What's the difference between window.open(url) and window.location.href = url on Firefox?
- What did the related answers not answer for you? developer.mozilla/en-US/docs/Web/API/Location/assign vs developer.mozilla/en-US/docs/Web/API/Window/open – mplungjan Commented Mar 22, 2017 at 15:24
2 Answers
Reset to default 5Functionally? Not much. They do similar things in different ways.
Personally, I'd probably choose window.location over window.open. Even though they do the same things, using window.location for changing the current window is more mon, and doesn't require knowing about '_self', which isn't used that often. My experience is my coworkers expect window.open to involve opening a window versus reusing the same one.
window.location.assign
will assign the current window a new URL value. window.open
will open a new window (which may be in a new tab, or not, depending) with the value of the url passed.
It's the difference between creating a new window and editing an existing window.