人人人妻人人人妻人人人,99精品国产综合久久久久五月天 ,欧美白人最猛性XXXXX,日韩AV无码免费播放

News新聞

業(yè)界新聞動(dòng)態(tài)、技術(shù)前沿
Who are we?

您的位置:首頁(yè)      JS/JQ/AJAX      404頁(yè)面跳轉(zhuǎn)的5種方法

404頁(yè)面跳轉(zhuǎn)的5種方法

標(biāo)簽: 發(fā)布日期:2014-03-06 00:00:00 863
有的時(shí)候需要對(duì)網(wǎng)站的404頁(yè)面進(jìn)行設(shè)置,要求進(jìn)入404頁(yè)面5秒后,自動(dòng)跳轉(zhuǎn)到同目錄下的index.html(根據(jù)自己需要自行修改)文件。以下是5種跳轉(zhuǎn)的例子:
 
1) html的實(shí)現(xiàn)
 
 
<head>
<!-- 以下方式只是刷新不跳轉(zhuǎn)到其他頁(yè)面 -->
<meta http-equiv="refresh" content="10">
<!-- 以下方式定時(shí)轉(zhuǎn)到其他頁(yè)面 -->
<meta http-equiv="refresh" content="5;url=index.html"> 
</head>
優(yōu)點(diǎn):簡(jiǎn)單
缺點(diǎn):Struts Tiles中無(wú)法使用
 
 
2) javascript的實(shí)現(xiàn)
 
<script language="javascript" type="text/javascript"> 
// 以下方式直接跳轉(zhuǎn)
window.location.href='index.html';
// 以下方式定時(shí)跳轉(zhuǎn)
setTimeout("javascript:location.href='index.html'", 5000); 
</script>
優(yōu)點(diǎn):靈活,可以結(jié)合更多的其他功能
缺點(diǎn):受到不同瀏覽器的影響
3) 結(jié)合了倒數(shù)的javascript實(shí)現(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='index.html'; 
</script>
 
優(yōu)點(diǎn):更人性化
缺點(diǎn):firefox不支持(firefox不支持span、div等的innerText屬性)
3') 結(jié)合了倒數(shù)的javascript實(shí)現(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 = 'index.html'; 
</script>
 
4) 解決Firefox不支持innerText的問(wèn)題
 
 
 <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 = 'index.html'; 
} else { 
if (navigator.appName.indexOf("Explorer") > -1) { 
document.getElementById('totalSecond').innerText = second--; 
} else { 
document.getElementById('totalSecond').textContent = second--; 
</script>