DIV CSS 佈局教程網

window.location 與 window.open 打開頁面的區別
編輯:JavaScript基礎知識     

在 JavaScript 中開啟或跳轉頁面,常見的做法有三種,它們在行為上各有差異。

window.location = "https://www.xxxxxxxx.net"
這種寫法會在目前的視窗中跳轉,跳轉後仍保留返回(後退)功能。嚴格來說應寫成 window.location.href。

window.location.replace("https://www.xxxxxxxx.net")
同樣是在目前視窗跳轉,但跳轉後不具有返回功能——它會用新頁面取代目前的歷史記錄。

window.open("https://www.xxxxxxxx.net")
會在一個新視窗中打開連結。這種方式一般用於簡單的彈出頁面,不過現在由於大量瀏覽器都會攔截彈出視窗,使用上已大受限制。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved