• 本站在不影响浏览的前提下添加了少量广告,请允许本站广告可显示,感谢~
  • 如果有必要,请使用Telegram关注https://t.me/getssr_info
  • 关于国内某个软件代理商代理的CorelDRAW系列软件,如果各位需要正版请访问corel官方网站,不要访问带有china的网站!!!反正话是放在这里了,听不听随你
  • 如果遇到文章图片不显示请联系管理员处理,谢谢
  • 欢迎访问寡人的吐槽胜地,我们真的只是吐槽,不谈技术,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站
  • 版权声明:大部分文章是从网上复制的!并不表示全部都是从网上复制的!

HTML页面跳转的5种方法

网页设计 大变态 8年前 (2016-06-06) 1671次浏览 已收录 0个评论

下面列了五个例子来详细说明,这几个例子的主要功能是:在 5 秒后,自动跳转到同目录下的 hello.html(根据自己需要自行修改)文件。
1) html 的实现

<head>
<!-- 以下方式只是刷新不跳转到其他页面 -->
<meta http-equiv="refresh" content="10">
<!-- 以下方式定时转到其他页面 -->
<meta http-equiv="refresh" content="5;url=hello.html">
</head>
优点:简单
缺点:Struts Tiles 中无法使用
 2) javascript 的实现
<script language="javascript" type="text/javascript">
// 以下方式直接跳转
window.location.href='hello.html';
// 以下方式定时跳转
setTimeout("javascript:location.href='hello.html'", 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='hello.html';
}
</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 = 'hello.html';
}
</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 = 'hello.html';
} else {
    if (navigator.appName.indexOf("Explorer") > -1) {
        document.getElementById('totalSecond').innerText = second--;
    } else {
        document.getElementById('totalSecond').textContent = second--;
    }
}
}
</script>

本站大部分资源收集于网络,只做学习和交流使用,版权归原作者所有;若为付费内容,请在下载后 24 小时之内自觉删除,若作商业用途请购买正版;如果有版权争议,请发送邮件至 master@digac.cc(请留下写明原因和文章链接),我们将及时处理,谢谢!

喜欢 (0)
大变态
关于作者:
头像
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址