温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

网页实现自动跳转

发布时间:2020-07-28 19:49:18 来源:网络 阅读:588 作者:101ttyy 栏目:开发技术

两种实现自动跳转的的方法:

第一种方法,没有剩余秒数显示。

 

<meta http-equiv=refresh content='5;url="http://xxxx.com/"' />

第一种网页自动跳转方法:meta refresh自动跳转法 在网页的head区域的meta refresh标签中,加入自动跳转代码,可实现网页的立即或延时自动跳转。 示例如下: <meta http-equiv="refresh" content="10;url= http://xxxx.com/ "> 上述html代码中的“10”是延时跳转的时间,单位是秒。如果设为0,就表示立即跳转。“ http://xxxx.com/ ”是跳转的目标地址,可以是同一域名下的站内相对路径,也可以是不同域名的站外地址。 由于搜索引擎能够读取html,所以对于这种自动跳转方法,搜索引擎是能够自动检测出来的。 被视为作弊,则主要看跳转时间。如果跳转时间为0,就可能会被视为作弊,从而受到惩罚。如果有时间延迟(一般3秒以上),就会被视为正常应用。


第二种跳转方法,有剩余秒数显示。

  

    <script type="text/javascript">
     var duration = 10000;
        var timer = null;
        var endTime = new Date().getTime() + duration;
        function interval() {
            var timeSecond = (endTime - new Date().getTime()) / 1000;
            if (timeSecond  < 0) return;
            //toFixed() 方法可把 Number 四舍五入为指定小数位数的数字。
            $("#timeout").text(timeSecond .toFixed(0));
            setTimeout(interval, 10);
        }
        function stopJump() {
            clearTimeout(timer);
            $("#jumphint").style.display = "none";
        }
        window.onload = function() {
            timer = setTimeout("window.location.href='http://xxxx.com'", duration);
            interval();
        }
        </script>
        
        <span id="jumphint">系统在 <span id="timeout"></span> 秒后 将自动到首页</span>


setTimeout( ) 是属于 window 的 method, 但我们都是略去 window 这顶层物件名称, 这是用来设定一个时间, 时间到了, 就会执行一个指定的 method。请先看以下一个简单, 这是没有实际用途的例子, 只是用来示范 setTimeout( ) 的语法。

<script>
setTimeout("alert('
对不起, 要你久候')", 3000 )
</script>

setTimeout( )是设定一个指定等候时间 (单位是千分之一秒, millisecond), 时间到了, 浏览器就会执行一个指定的 method 或 function, 有以下语法:

今次例子是设定等 3 秒 (3000 milliseconds), 浏览器就会执行 alert( ) 这一个method。

setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式。

参考:

 http://www.w3school.com.cn/jsref/met_win_settimeout.asp

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI