HTML页面自动跳转的五种实现方法
2010-10-27 10:27
931 查看
下面列了五个例子来详细说明,这几个例子的主要功能是:在5秒后,自动跳转到同目录下的hello.html(根据自己需要自行修改)文件。
1)html的实现view plain
copy to clipboard
?
<
head
>
<
meta
http-equiv
=
"refresh"
content
=
"5;url=hello.html"
>
</
head
>
<head> <meta http-equiv="refresh" content="5;url=hello.html"> </head>
优点:简单
缺点:Struts Tiles中无法使用
2)javascript的实现
view plain
copy to clipboard
?
<
mce:script
language
=
"javascript"
type
=
"text/javascript"
>
<!--
setTimeout("javascript:location.href
=
'http://liting6680.blog.163.com/blog/hello.html'
", 5000);
// -->
</
mce:script
>
<mce:script language="javascript" type="text/javascript"><!-- setTimeout("javascript:location.href='http://liting6680.blog.163.com/blog/hello.html'", 5000); // --></mce:script>
优点:灵活,可以结合更多的其他功能
缺点:受到不同浏览器的影响
3)结合了倒数的javascript实现(IE)
view plain
copy to clipboard
?
<span id=
"totalSecond"
>5</span>
<mce:script language="javascript"
type=
"text/javascript"
><!--
var
second = totalSecond.innerText;
setInterval("redirect()"
, 1000);
function
redirect(){
totalSecond.innerText=--second;
if
(second<0) location.href=
'http://liting6680.blog.163.com/blog/hello.html'
;
}
// --></mce:script>
<span id="totalSecond">5</span> <mce:script language="javascript" type="text/javascript"><!-- var second = totalSecond.innerText; setInterval("redirect()", 1000); function redirect(){ totalSecond.innerText=--second; if(second<0) location.href='http://liting6680.blog.163.com/blog/hello.html'; } // --></mce:script>
优点:更人性化
缺点:firefox不支持(firefox不支持span、div等的innerText属性)
3
'
)结合了倒数的javascript实现(firefox)
view plain
copy to clipboard
?
<mce: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://liting6680.blog.163.com/blog/hello.html'
;
}
// --></mce:script>
<mce: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://liting6680.blog.163.com/blog/hello.html'; } // --></mce:script>
4)解决Firefox不支持innerText的问题
view plain
copy to clipboard
?
<span id=
"totalSecond"
>5</span>
<mce: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"
;
}
// --></mce:script>
<span id="totalSecond">5</span> <mce: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"; } // --></mce:script>
5)整合3)和3')
view plain
copy to clipboard
?
<span id=
"totalSecond"
>5</span>
<mce: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://liting6680.blog.163.com/blog/hello.html'
;
} else
{
if
(navigator.appName.indexOf(
"Explorer"
) > -1)
{
document.getElementById('totalSecond'
).innerText = second--;
} else
{
document.getElementById('totalSecond'
).textContent = second--;
}
}
}
// --></mce:script>
相关文章推荐
- html 页面自动跳转的五种实现方法
- HTML实现页面自动跳转的五种方法
- HTML页面自动跳转的五种实现方法
- HTML页面自动跳转的五种实现方法
- HTML页面自动跳转的五种实现方法
- HTML页面自动跳转的五种实现方法
- HTML页面自动跳转的五种实现方法
- HTML实现页面自动跳转的五种方法
- HTML页面自动跳转的五种实现方法
- HTML跳转页面的五种方法
- HTML页面3秒后自动跳转的三种常见方法
- 页面自动跳转实现方法
- 页面自动跳转的几种实现方法
- 页面自动跳转的几种实现方法
- 通过js实现页面跳转的五种方法
- 网站页面自动跳转实现方法PHP、JSP等
- java servlet 几种页面跳转的方法,需要的朋友可以参考一下 在访问网页的过程中,页面自动刷新、跳转和重定向是经常用到的,这里就说说在Java中是如何实现这些功能的! 一、页面自动刷新
- 网站页面自动跳转实现方法PHP、JSP(下)
- HTML页面跳转(重定向)的五种方法
- html和js实现页面跳转方法