之前的文章《一招教你使用css给HTML字体添加背景图》中,给大家介绍了怎样使用css给HTML字体添加背景图的方法。下面本篇文章给大家介绍使用html5怎么实现页面跳转的方法,有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所助。

下面列了五个例子来详细说明,这几个例子的主要功能是:在5秒后,自动跳转到同目录下的hello.html(根据自己需要自行修改)文件。
1、html的实现
优点:简单
缺点:Struts Tiles中无法使用
2、 javascript的实现
立即学习“前端免费学习笔记(深入)”;
// 以下方式直接跳转window.location.href='hello.html';// 以下方式定时跳转setTimeout("javascript:location.href='hello.html'", 5000);
优点:灵活,可以结合更多的其他功能
缺点:受到不同浏览器的影响
3、结合了倒数的javascript实现(IE)
5 var second = totalSecond.innerText; setInterval("redirect()", 1000); function redirect(){ totalSecond.innerText=--second; if(second<0) location.href='hello.html'; }
优点:更人性化
缺点:firefox不支持(firefox不支持span、p等的innerText属性)
4、结合了倒数的javascript实现(firefox)
var second = document.getElementById('totalSecond').textContent; setInterval("redirect()", 1000); function redirect() { document.getElementById('totalSecond').textContent = --second; if (second < 0) location.href = 'hello.html'; }
5、解决Firefox不支持innerText的问题
5 if(navigator.appName.indexOf("Explorer") > -1){ document.getElementById('totalSecond').innerText = "my text innerText"; } else{ document.getElementById('totalSecond').textContent = "my text textContent"; }
完整代码带3和4
5 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 -1) { document.getElementById('totalSecond').innerText = second--; } else { document.getElementById('totalSecond').textContent = second--; } } }
推荐学习:Html视频教程
以上就是html5篇:实现页面跳转的5种方式(代码分享)的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1550506.html
微信扫一扫
支付宝扫一扫