1,open()
打开一个新的浏览器窗口
<input type="button" value="去往新窗口按钮" onclick="fun1()">function fun1() {window.open("https://blog.csdn.net/daxiang12092205/article/details/11878477/")}
2,location.href
使用 location.href 属性可以设置或获取当前页面的 URL。通过将其值设置为新的 URL,可以实现页面跳转
function fun3() {
//返回当前页面
var url=window.location.href
alert(url)//返回完整的url
alert(location.host)
alert(location.hostname)
}function fun4(){
//去往新的链接
window.location.href="链接";
}
3.reload()
location.replace() 方法可以实现页面跳转
但与前两种方式不同的是,它会替换当前页面的历史记录
function fun6() {//替换----就跟一个链接一样location.replace("链接")}
4,history.go()
使用 history.go() 方法可以跳转到指定的历史记录索引。负数表示后退,正数表示前进
function fun2() {
//去往指定页面
window.history.go(-1)
}
5,alert(document.URL)
返回当前页面的url
function fun7() {
//返回当前页面的url
alert(document.URL)
}<input type="button" value="返回当前url" onclick="fun7()">
6,window.navigate()跳转
<script language="javascript">window.navigate("链接");
</script>
7,history.back()
使用 history.back() 方法可以让浏览器后退到历史记录中的上一个页面
<script language="javascript">alert("返回");window.history.back(-1);
</script>