相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
- 拉動(dòng)懸浮于頂部的JS控制代碼
- 在JavaScript中構(gòu)建ArrayList示例代碼
- js使用for循環(huán)及if語(yǔ)句判斷多個(gè)一樣的name
- JavaScript中判斷原生函數(shù)檢查function是否是原生代碼
- jQuery CSS()方法改變現(xiàn)有的CSS樣式表
- JavaScript中判斷原生函數(shù)檢查function是否是原生代碼
- jQuery動(dòng)畫(huà)高級(jí)用法(上)——詳解animation中的.queue()函數(shù)
- python小技巧之批量抓取美女圖片
- JS中offsetTop、clientTop、scrollTop、offsetTop各屬性介紹
- JS獲取瀏覽器窗口大小 獲取屏幕,瀏覽器,網(wǎng)頁(yè)高度寬度
404頁(yè)面跳轉(zhuǎn)的5種方法
有的時(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>