本文是本站小編搜索整理的五個實例給大家介紹html如何實現頁面自動跳轉,感興趣的朋友一起學習吧!!想了解更多相關信息請持續關注我們應屆畢業生考試網!
1)html的實現
代碼如下:
<head>
<meta http-equiv="refresh" content="5;url=">
</head>
優點:簡單
缺點:Struts Tiles中無法使用
2)javascript的實現
代碼如下:
<mce:script language="javascript" type="text/javascript"><!--
setTimeout("javascript:=''", 5000);
// --></mce:script>
優點:靈活,可以結合更多的'其他功能
缺點:受到不同瀏覽器的影響
3)結合了倒數的javascript實現(IE)
代碼如下:
<span id="totalSecond">5</span>
<mce:script language="javascript" type="text/javascript"><!--
var second = rText;
setInterval("redirect()", 1000);
function redirect(){
rText=--second;
if(second<0) ='';
}
// --></mce:script>
優點:更人性化
缺點:firefox不支持(firefox不支持span、p等的innerText屬性)
3 )結合了倒數的javascript實現(firefox)
代碼如下:
<mce:script language="javascript" type="text/javascript"><!--
var second = lementById('totalSecond')Content;
setInterval("redirect()", 1000);
function redirect()
{
lementById('totalSecond')Content = --second;
if (second < 0) ='';
}
// --></mce:script>
4)解決Firefox不支持innerText的問題
代碼如下:
<span id="totalSecond">5</span>
<mce:script language="javascript" type="text/javascript"><!--
if(xOf("Explorer") > -1){
lementById('totalSecond')rText = "my text innerText";
} else{
lementById('totalSecond')Content = "my text textContent";
}
// --></mce:script>
5)整合3)和3')
代碼如下:
<span id="totalSecond">5</span>
<mce:script language="javascript" type="text/javascript"><!--
var second = lementById('totalSecond')Content;
if (xOf("Explorer") > -1)
{
second = lementById('totalSecond')rText;
} else
{
second = lementById('totalSecond')Content;
}
setInterval("redirect()", 1000);
function redirect()
{
if (second < 0)
{
='';
} else
{
if (xOf("Explorer") > -1)
{
lementById('totalSecond')rText = second--;
} else
{
lementById('totalSecond')Content = second--;
}
}
}
// --></mce:script>