为了账号安全,请及时绑定邮箱和手机立即绑定

js技巧专题篇: 页面跳转

本篇主要介绍网页上常见的页面跳转技术。页面跳转有几种方式,比较常用的是window.location.href,window.location.replace,window.open,当然还有目前比较火的很多框架都采用的无刷新页面跳转技术window.history.pushState和window.history.replaceState。这些我都不讲^_^,我这里讲得是meta的一个相关配置。我相信,很多朋友看见实现的页面时会非常面熟,特别是男性!

以下是相关代码实现:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="refresh" content="5;url=https://www.baidu.com"/>
    <title></title>
    <style>
        span {
            color: red;
            padding: 5px 15px;
            background: #cccccc;
        }
        button {
            padding: 10px;
            display: inline-block;
            vertical-align: top;
            border-radius: 4px;
            outline: none;
        }
    </style>
</head>
<body>
<h1>对不起您浏览的页面已改变,<span>5</span> 秒后自动为您跳转... <button>手动跳转</button></h1>
<script>
    var span = document.querySelector('span'),
            btn = document.querySelector('button');
    var selfTimer = (function(){
        var i = 5;
        return function(){
            span.innerHTML = --i;
            if (i == 0) {
                clearInterval(timer);
            }
        }
    })()
   timer = setInterval(selfTimer, 1000);

    btn.onclick = function() {
        window.location.hash = 'https://www.baidu.com';
    }
    </script>
</body>
</html>

哈哈哈,如果有人运行这段代码就懂了^_^,就差一个我们的新网址是1024,懂的自然懂。

点击查看更多内容
29人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
Web前端工程师
手记
粉丝
9110
获赞与收藏
2572

关注作者,订阅最新文章

阅读免费教程

感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消