js(jquery)實現(xiàn)無刷新跳轉(zhuǎn)404頁面不存在效果
有時候我們希望臨時讓某個分類或者多個文章不能正常訪問,手動給html文件改名?或者改后臺改程序?太麻煩了。用本文的js代碼很容易實現(xiàn),而且使用得當(dāng)很隱蔽。
html代碼示例如下,注意需要jquery
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>測試404頁面不存在</title>
<script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">window.Configs={"typeid":1,"id":469};</script>
<script>
if ("undefined" != typeof window.Configs && (window.Configs.typeid !=2 || window.Configs.id !=469)) {
var errHtml = '<div class="error-page-wrap"><em>404</em><h1>\u62b1\u6b49\uff01\u60a8\u8bbf\u95ee\u7684\u9875\u9762\u4e0d\u5b58\u5728</h1><p>\u00b7\u8be5\u9875\u9762\u53ef\u80fd\u5df2\u7ecf\u5220\u9664\u6216\u66f4\u540d
\u00b7\u8bf7\u68c0\u67e5\u8f93\u5165\u7684\u5730\u5740\u662f\u5426\u6b63\u786e</p><a href="/" class="home404">\u8fd4\u56de\u9996\u9875</a></div>';
(lookupCallEnabled = !1,
document.title = "404-\u9875\u9762\u4e0d\u5b58\u5728",
jQuery("html").hide(),
jQuery(function(a) {
a("body").html(errHtml);
a("html").show();
a("body").css("background", "#fff")
})
);
}
</script>
<style>
.error-page-wrap{width:100%;background:#ffffff;font-size:13px;margin:40px auto;padding:20px 10px;text-align:center;overflow:hidden}
.error-page-wrap a {color:#333;text-decoration:none;}
.error-page-wrap em{width:225px;height:45px;margin:0 auto;text-indent:-999em;display:inline-block;overflow:hidden;background:url(/static/image/logo404.png) no-repeat;}
.error-page-wrap h1{font-size:24px;color:#c71508;font-family:'Microsoft Yahei', Georgia;margin:10px 0 20px ;}
.error-page-wrap p{line-height:28px;}
.error-page-wrap .home404{width:92px;line-height:28px;height:28px;display:inline-block;border-radius:3px;background:#2A9325;font-weight:bold;color:#fff;text-align:center;margin:15px 0 0 6px;overflow:hidden;cursor:pointer;}
</style>
</head>
<body>
<div>js(jquery)實現(xiàn)無刷新跳轉(zhuǎn)404頁面不存在效果</div>
</body>
</html>代碼講解:
1. https://apps.bdimg.com/libs/jquery/1.11.3/jquery.min.js——是百度的jquery靜態(tài)資源,穩(wěn)定高速;
2. window.Configs={"typeid":1,"id":469}; ——程序調(diào)出分類typeid值,文章id值;
3. "undefined" != typeof window.Configs——判斷window.Configs是否存在,未定義返回"undefined";
4. window.Configs.typeid !=2 || window.Configs.id !=469——分類typeid值不等于2或者文章id值不等于469,根據(jù)實際情況,這里可以使用多種匹配;
5. errHtml——定義的頁面展示HTML代碼;
6. document.title——標(biāo)題;
隱蔽使用:
可以把js代碼藏到其他js文件中,或者js加密等等。
到此這篇關(guān)于js(jquery)實現(xiàn)無刷新跳轉(zhuǎn)404頁面不存在效果的文章就介紹到這了,更多相關(guān)js無刷新跳轉(zhuǎn)404頁面不存在內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
實例詳解JSON數(shù)據(jù)格式及json格式數(shù)據(jù)域字符串相互轉(zhuǎn)換
JSON(JavaScript Object Notation)是一種輕量級的數(shù)據(jù)交換格式。JSON采用完全獨(dú)立于語言的文本格式,這些特性使JSON成為理想的數(shù)據(jù)交換語言2016-01-01
基于JavaScript實現(xiàn)抽獎系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了基于JavaScript實現(xiàn)抽獎系統(tǒng),具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-01-01

