location.href、location.assign和location.replace的区别
生活随笔
收集整理的這篇文章主要介紹了
location.href、location.assign和location.replace的区别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在寫跳轉頁面的時候遇到個有意思的問題,RT的三個均能用來寫跳轉,總結了下它們之間的區別。
1、window.location.href=“url”; ? ? ?改變url地址。
location.href是一個屬性,要這樣寫:location.href="url"
2、window.location.assign("url") ?加載新的文檔,效果與location.href相當。?
3、window.location.replace ?將地址替換成新url,該方法通過指定URL替換當前緩存在歷史里(客戶端)的項目。
與以上兩者的區別在于:在replace之后,瀏覽歷史就被清空了(href與assign方法會產生歷史記錄)。
因此若使用replace頁面跳轉后是不能后退的。
?
轉載于:https://www.cnblogs.com/liu-l/p/3835714.html
總結
以上是生活随笔為你收集整理的location.href、location.assign和location.replace的区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 二、mysql数据类型
- 下一篇: codeigniter文件上传问题