Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between window.location.assign(url) and window.open(url, '_self')

Tags:

javascript

dom

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?
like image 733
Ryan Li Avatar asked May 04 '15 00:05

Ryan Li


1 Answers

Functionally? 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 common, 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.

like image 120
Michael Landis Avatar answered Sep 23 '22 01:09

Michael Landis