最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Difference between window.location.assign(url) and window.open(url, '_self') - Stack Overflow

programmeradmin4浏览0评论

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?
Share Improve this question edited May 30, 2017 at 16:20 Ryan Li asked May 4, 2015 at 0:32 Ryan LiRyan Li 9,3587 gold badges35 silver badges64 bronze badges 1
  • 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
Add a ment  | 

2 Answers 2

Reset to default 5

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论