当前页面替换成新页面
- replace() 方法可用一个新文档取代当前文档。
location.replace(newURL);
window.location.replace("https://www.dududu.com");
- href 属性是一个可读可写的字符串,可设置或返回当前显示的文档的完整 URL
// 打印出返回的当前页面url
document.write(location.href);
// 通过设置来跳转(设置后立即跳转)
window.location.href='http://www.baidu.com';
打开新页面
open() 方法用于打开一个新的浏览器窗口或查找一个已命名的窗口。
window.open("http://www.baidu.com");
html自动跳转:
注:若不设.html扩展名,需要设置标签来让浏览器识别为html。
例:等待0秒,刷新到‘url=’指定的路径,不指定url则为当前路径
<html>
<meta http-equiv="refresh" content="0;url=a.html">
</html>