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";