window.location對象可用於獲取當前頁面地址(url)並把瀏覽器重定向到新頁面。html
window.location 對象可不帶 window 前綴書寫。web
一些例子:瀏覽器
window.location.assign() 方法加載新文檔。url
加載新文檔:spa
<!DOCTYPE html> <html> <body> <h1>window.location 對象</h1> <input type="button" value="加載新的文檔" onclick="newDoc()"> <script> function newDoc() { window.location.assign("http://www.w3school.com.cn") } </script> </body> </html>