架构师_程序员_码农网

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 8603|回复: 0

[建站知识] html 301跳转 html如何做跳转

[复制链接]
发表于 2014-10-26 17:19:00 | 显示全部楼层 |阅读模式
html是做不了301跳转的,但是可以通过
在5秒后,自动跳转到同目录下的hello.html(根据自己需要自行修改)文件。
下面列了五个例子来详细说明,这几个例子的主要功能是:在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)
<script language="javascript" type="text/javascript">
var second = document.getElementByIdx_x('totalSecond').textContent;
setInterval("redirect()", 1000);
function redirect()
{
document.getElementByIdx_x('totalSecond').textContent = --second;
if (second < 0) location.href = 'hello.html';
}
</script>





优点:更人性化
缺点:firefox不支持(firefox不支持span、div等的innerText属性)
3') 结合了倒数的javascript实现(firefox)
<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>

4) 解决Firefox不支持innerText的问题
<span id="totalSecond">5</span>
<script language="javascript" type="text/javascript">
if(navigator.appName.indexOf("Explorer") > -1){
document.getElementByIdx_x('totalSecond').innerText = "my text innerText";
} else{
document.getElementByIdx_x('totalSecond').textContent = "my text textContent";
}
</script>



5) 整合3)和3')


<span id="totalSecond">5</span>

<script language="javascript" type="text/javascript">
var second = document.getElementByIdx_x('totalSecond').textContent;

if (navigator.appName.indexOf("Explorer") > -1)  {
    second = document.getElementByIdx_x('totalSecond').innerText;
} else {
    second = document.getElementByIdx_x('totalSecond').textContent;
}

setInterval("redirect()", 1000);
function redirect() {
if (second < 0) {
    location.href = 'hello.html';
} else {
    if (navigator.appName.indexOf("Explorer") > -1) {
        document.getElementByIdx_x('totalSecond').innerText = second--;
    } else {
        document.getElementByIdx_x('totalSecond').textContent = second--;
    }
}
}
</script>






上一篇:完美过D盾,安全狗的php一句话
下一篇:大一上学期“厚朴公司”Java课件第2、4、5、6、7章课件
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

免责声明:
码农网所发布的一切软件、编程资料或者文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:help@itsvse.com

QQ|手机版|小黑屋|架构师 ( 鲁ICP备14021824号-2 )|网站地图

GMT+8, 2024-5-29 13:10

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表