实现网页自动跳到其他页面的几种方法

某些时候我们需要实现网页的自动跳转,比如404错误页可以加入代码让它自动跳转到首页,下面介绍三种html页面自动跳转的方法。

方法一:页面在头部加入meta标签
在头部加入 <meta http-equiv="refresh" content="时间/s;url=网址/http://www.idblog.cn">  

代码如下: 

<html>
<head>
    <meta charset="UTF-8">
    <title>html自动跳转</title>
    <meta http-equiv="refresh" content="3;url=http://www.idblog.cn">
</head>
<body>

</body>
</html>

方法二:script实现自动跳转
第一种:比较常用:window.location.href = "http://baidu.com/";

代码如下:

<html>
<head>
    <title>html自动跳转</title>
</head>
<body>
<script>
    document.location = 'http://www.w3h5.com'
</script>
</body>
</html>

第二种:

self.location = "http://baidu.com/";

第三种:

top.location = "http://baidu.cn/";

第四种:只对IE系列浏览器有效,实用性不大。

window.navigate("http://baidu.cn/");

方法三:PHP实现

<?php
    header("Location: http://baidu.cn/");
?>

方法四:动态显示的自动跳转代码(比较复杂,不推荐)

TIM截图20170804132709.png 实现网页自动跳到其他页面的几种方法 HTML笔记

<html>
<head>
    <meta charset="UTF-8">
    <title>html自动跳转</title>
</head>
<body>
<form name=loading>
    <p align=center>
        <font color="#0066ff" size="2">正在跳转,请稍等</font><font color="#0066ff" size="2" face="Arial">...</font>
        <input type=text name=chart size=46
               style="font-family:Arial; font-weight:bolder; color:#0066ff; background-color:#fef4d9; padding:0px; border-style:none;">
        <input type=text name=percent size=47
               style="color:#0066ff; text-align:center; border-width:medium; border-style:none;">
        <script>
            var bar = 0
            var line = "||"
            var amount = "||"
            count()

            function count() {
                bar = bar + 2
                amount = amount + line
                document.loading.chart.value = amount
                document.loading.percent.value = bar + "%"
                if (bar < 99) {
                    setTimeout("count()", 100);
                }
                else {
                    window.location = "http://www.idblog.cn";
                }
            }
        </script>
    </p>
</form>
<p align="center"> 如果您的浏览器不支持跳转,
    <a style="text-decoration: none" href="http://www.idblog.cn">
        <font color="#FF0000">请点这里</font>
    </a>.
</p>
</body>
</html>


未经允许不得转载:Web前端开发资源网 » 实现网页自动跳到其他页面的几种方法

推荐阅读:

判断网页是通过PC端还是移动终端打开的

Discuz X3.4 MySQL数据库连接问题的解决方法

WDLinux故障 Linux系统网站数据备份笔记

2018年4月24日 服务器换成腾讯云

JetBrains IDE Support 浏览器自动刷新插件(不定时更新)

赞 (3)
分享到: +

评论 沙发

Avatar

换个身份

  • 昵称 (必填)
  • 邮箱 (选填)