html和JavaScript如何实现跳转页面

这篇文章将为大家详细讲解有关html和JavaScript如何实现跳转页面,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

跳转页面的方法:1、html中可以利用meta标签进行跳转,语法“”;2、javascript中可以利用location对象的href属性进行跳转,语法“window.location.href=页面地址”。

html/JavaScript实现页面跳转

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

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

2、通过javascript中实现跳转

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

html跳转上一页的方式

window.history.go(-1);或者window.history.back(-1);

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

关于“html和JavaScript如何实现跳转页面”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。