当前位置:首页运维笔记HTML页面跳转的5种方法

HTML页面跳转的5种方法

1) html的实现

[success]<head>
<!– 以下方式只是刷新不跳转到其他页面 –>
<meta http-equiv=”refresh” content=”10″>
<!– 以下方式定时转到其他页面 –>
<meta http-equiv=”refresh” content=”5;url=hello.html”>
</head>[/success]

优点:简单
缺点:Struts Tiles中无法使用

2) javascript的实现

[success]<script language=”javascript” type=”text/javascript”>
// 以下方式直接跳转
window.location.href=’hello.html’;
// 以下方式定时跳转
setTimeout(“javascript:location.href=’hello.html'”, 5000);
</script>[/success]
优点:灵活,可以结合更多的其他功能
缺点:受到不同浏览器的影响

3) 结合了倒数的javascript实现(IE)
[success]<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=’hello.html’;
}
</script>[/success]
优点:更人性化
缺点:firefox不支持(firefox不支持span、div等的innerText属性)

3′) 结合了倒数的javascript实现(firefox)
[success]<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 = ‘hello.html’;
}
</script>[/success]

4) 解决Firefox不支持innerText的问题
[success]<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>[/success]

5) 整合3)和3′)

[success]

<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 = ‘hello.html’;
} else {
if (navigator.appName.indexOf(“Explorer”) > -1) {
document.getElementById(‘totalSecond’).innerText = second–;
} else {
document.getElementById(‘totalSecond’).textContent = second–;
}
}
}
</script>

[/success]

 

温馨提示:

文章标题:HTML页面跳转的5种方法

文章链接:https://p1e.cn/html/694.html

更新时间:2019年05月25日

本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:815494#qq.com我们将第一时间处理! 资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。 所有资源仅限于参考和学习,版权归原作者所有。

给TA打赏
共{{data.count}}人
人已打赏
运维笔记

DD-WinSrv2008r2x64-sp1-数据中心版-精简,支持KVM/Xen/Hyper

2018-11-12 16:46:20

运维笔记

优秀免费数据恢复软件 Wondershare Recoverit 万兴数据恢复专家中文免费版

2018-12-5 9:46:25

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索