window.open(‘index.html’)
表示新增一個窗口打開 index.html 這個頁面,並不刷新。
window.location.href(‘index.html’)
表示在當前窗口重定向到新頁面,打開並刷新 index.html 這個頁面。
window.location 是 window 對象的屬性,用來替換當前頁,也就是重新定位當前頁。
而window.open 是 window 對象的方法,是用來打開一個新窗口的函數。
// 打開新頁面
// 注意:有些瀏覽器的安全設置會將window.open()屏蔽,例如避免彈出廣告窗
window.open('./index.html');
// 在原窗口打開新頁面
window.location.href="./index.html";