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

javascript - What is the difference between location.replace and location.href? - Stack Overflow

programmeradmin3浏览0评论

What is the difference between the two :

location.replace(url)

and

location.href = url

I read that the first method stimulates HTTP redirect and the second one is similar, to following a web-page by clicking a link.

But I do not understand really,what does that mean.

What is the difference between the two :

location.replace(url)

and

location.href = url

I read that the first method stimulates HTTP redirect and the second one is similar, to following a web-page by clicking a link.

But I do not understand really,what does that mean.

Share Improve this question edited Sep 5, 2014 at 20:56 Timo Tijhof 10.3k6 gold badges37 silver badges53 bronze badges asked Oct 2, 2013 at 6:02 Suhail GuptaSuhail Gupta 23.3k66 gold badges212 silver badges344 bronze badges 2
  • 3 possibly duplicate http://stackoverflow./questions/1865837/whats-the-difference-between-window-location-and-window-location-replace – jasonslyvia Commented Oct 2, 2013 at 6:04
  • 2 possible duplicate of Difference between window.location.href, window.location.replace and window.location.assign – fiskeben Commented Oct 2, 2013 at 6:05
Add a ment  | 

1 Answer 1

Reset to default 13

location.replace doesn't update the browser's history, you can't press the back button, location.href is pretty much like clicking on a link.

The Location.replace()method replaces the current resource 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.

Source : MDN

发布评论

评论列表(0)

  1. 暂无评论