一些頁面自動跳轉(zhuǎn)的實現(xiàn)
系統(tǒng)
1641 0
功能:5秒后,自動跳轉(zhuǎn)到同目錄下的02view.html文件
1)html的實現(xiàn)
<
head
>
<
meta
http-equiv
="refresh"
content
="5;url=02view.html"
>
</
head
>
優(yōu)點:簡單
缺點:Struts Tiles中無法使用
2)javascript的實現(xiàn)
<
script
language
="javascript"
type
="text/javascript"
>
setTimeout(
"
javascript:location.href='02view.html'
"
,
5000
);
</
script
>
優(yōu)點:靈活,可以結(jié)合更多的其他功能
缺點:受到不同瀏覽器的影響
3)結(jié)合了倒數(shù)的javascript實現(xiàn)(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
=
'02view.html';
}
</
script
>
優(yōu)點:更人性化
缺點:firefox不支持(firefox不支持span、div等的innerText屬性)
3')結(jié)合了倒數(shù)的javascript實現(xiàn)(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
=
'02view.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
=
"
mytextinnerText
"
;
}
else
{
document.getElementById('totalSecond').textContent
=
"
mytexttextContent
"
;
}
</
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
=
'02view.html';
}
else
{
if
(navigator.appName.indexOf(
"
Explorer
"
)
>
-
1
)
{
document.getElementById('totalSecond').innerText
=
second
--
;
}
else
{
document.getElementById('totalSecond').textContent
=
second
--
;
}
}
}
</
script
>
一些頁面自動跳轉(zhuǎn)的實現(xiàn)
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元