使用JavaScript重定向到其他網頁的一些方法:
-
location.href
-
location.replace()
-
location.assign()
語法:
window.location.href="URL" //或者
location.replace("URL") //或者
location.assign("URL")
參數:
接受單個參數的URL,這是必需的。用於指定新網頁的引用。
返回值:
無返回值。
注意:
所有方法的輸出都相同,但location.replace()方法從文檔歷史記錄中刪除當前文檔的URL。因此,如果希望選項導航回原始文檔,最好使用location.assign()方法。