微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

网页自动跳转代码|HTML自动跳转代码

有时我们要对网页做跳转,让用户打开该页面后马上或是在一定的时间内跳转到另外一个页面,下面小编分享网页自动跳转代码给大家。

跳转代码方案一,用<Meta>里直接写刷新语句:

如下语句,红色甩部分改成自己的网页地址就好了。蓝色部分为跳转时间 下面是5秒,可以改成自己需要的时间,0表示不等待。

<html>

< head>

< Meta http-equiv=Content-Language content=zh-CN>

< Meta HTTP-EQUIV=Content-Type CONTENT=text/html; charset=gb2312>

< Meta http-equiv=refresh content=5;url=http://www..com>

< title>html网页自动跳转代码--西农大网站</title>

< /head>

< body>

测试:html网页自动跳转代码<br/>

这里可以写一些文字,在跳转之前可以显示用户!<br />

</body>

< /html>

自动跳转代码方案二,用JavaScript脚本来跳转

2) javascript的实现

<script language=javascript type=text/javascript>

// 以下方式直接跳转

window.location.href='hello.html';

// 以下方式定时跳转

setTimeout(javascript:location.href='http://www..com',5000);

</script>

优点:灵活,可以结合更多的其他功能

缺点:受到不同浏览器的影响

3) 结合了倒数的javascript实现(IE)

<span id=totalSecond>5</span>

<script language=javascript type=text/javascript>

var second = totalSecond.innerText;

setInterval(redirect(),1000);

function redirect(){

totalSecond.innerText=--second;

if(second<0) location.href='http://www..com';

}

</script>

优点:更人性化

缺点:firefox不支持(firefox不支持span、div等的innerText属性

3') 结合了倒数的javascript实现(firefox)

<script language=javascript type=text/javascript>

var second = document.getElementById('totalSecond').textContent;

setInterval(redirect(),1000);

function redirect()

{

document.getElementById('totalSecond').textContent = --second;

if (second < 0) location.href = 'http://www..com';

}

</script>

4) 解决Firefox不支持innerText的问题

<span id=totalSecond>5</span>

<script language=javascript type=text/javascript>

if(navigator.appName.indexOf(Explorer) > -1){

document.getElementById('totalSecond').innerText = my text innerText;

} else{

document.getElementById('totalSecond').textContent = my text textContent;

}

</script>

5) 整合3)和3')

<span id=totalSecond>5</span>

<script language=javascript type=text/javascript>

var second = document.getElementById('totalSecond').textContent;

if (navigator.appName.indexOf(Explorer) > -1) {

second = document.getElementById('totalSecond').innerText;

} else {

second = document.getElementById('totalSecond').textContent;

}

setInterval(redirect(),1000);

function redirect() {

if (second < 0) {

location.href = 'http://www..com';

} else {

if (navigator.appName.indexOf(Explorer) > -1) {

document.getElementById('totalSecond').innerText = second--;

} else {

document.getElementById('totalSecond').textContent = second--;

}

}

}

</script>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐