HTML+JS中网页跳转的写法

2019-06-02  本文已影响0人  elileo

1、html中使用meta中跳转,通过meta可以设置跳转时间和页面

<head>
    <!--只是刷新不跳转到其他页面 -->
    <meta http-equiv="refresh" content="5">
    <!--定时转到其他页面 -->
    <meta http-equiv="refresh" content="5;url=index.html"> 
</head>

2、通过javascript中实现跳转

// 直接跳转
window.location.href='index.html';
// 定时跳转
setTimeout("javascript:location.href='index.html'", 5000);

3、html跳转上一页的方式

<script type="text/javascript">
    var wrong = document.getElementById('btn');
    wrong.onclick = function() { 
    window.history.go(-1);//返回上一页
    window.history.back(-1);//返回上一页
   }
</script>

在html中写

<a href=”#” onClick=”JavaScript :history.back(1);”>返回上一页</a>
<a href=”#” onClick=”javascript :history.Go(-1);”>返回上一页</a>

在Js中网页跳转的写法

1、window.location.href

window.location.href="http://www.baidu.com"; //在原有窗口打开

2.window.navigate方式跳转

window.navigate("http://www.baidu.com");

function toBooks() {
    
    //在原有窗口打开
    window.location.href = "http://www.baidu.com";
    //打开新的窗口
    window.open("http://www.baidu.com");
}

直接跳转加参数

<script language="javascript" type="text/javascript">
           window.location.href="login.jsp?backurl="+window.location.href; 
</script>
上一篇 下一篇

猜你喜欢

热点阅读