js怎么实现无刷新跳转404页面不存在效果


本文小编为大家详细介绍“js怎么实现无刷新跳转404页面不存在效果”,内容详细,步骤清晰,细节处理妥当,希望这篇“js怎么实现无刷新跳转404页面不存在效果”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

html代码示例如下,注意需要jquery

<!DOCTYPEhtml><htmlxmlns="w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><title>测试404页面不存在</title><scripttype="text/javascript"src="apps.bdimg/libs/jquery/1.11.3/jquery.min.js"></script><scripttype="text/javascript">window.Configs={"typeid":1,"id":469};</script><script>if("undefined"!=typeofwindow.Configs&&(window.Configs.typeid!=2||window.Configs.id!=469)){varerrHtml='<divclass="error-page-wrap"><em>404</em><h2>\u62b1\u6b49\uff01\u60a8\u8bbf\u95ee\u7684\u9875\u9762\u4e0d\u5b58\u5728</h2><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><ahref="/"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")(errHtml);a("html").show();a("body").css("background","#fff")}));}</script><style>.error-page-wrap{width:100%;background:#ffffff;font-size:13px;margin:40pxauto;padding:20px10px;text-align:center;overflow:hidden}.error-page-wrapa{color:#333;text-decoration:none;}.error-page-wrapem{width:225px;height:45px;margin:0auto;text-indent:-999em;display:inline-block;overflow:hidden;background:url(/static/image/logo404.png)no-repeat;}.error-page-wraph2{font-size:24px;color:#c71508;font-family:'MicrosoftYahei',Georgia;margin:10px020px;}.error-page-wrapp{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:15px006px;overflow:hidden;cursor:pointer;}</style></head><body><div>js(jquery)实现无刷新跳转404页面不存在效果</div></body></html>

代码讲解:

1. apps.bdimg/libs/jquery/1.11.3/jquery.min.js&mdash;&mdash;是百度的jquery静态资源,稳定高速;

2.window.Configs={"typeid":1,"id":469}; &mdash;&mdash;程序调出分类typeid值,文章id值;

3."undefined" != typeof window.Configs&mdash;&mdash;判断window.Configs是否存在,未定义返回"undefined";

4. window.Configs.typeid !=2 || window.Configs.id !=469&mdash;&mdash;分类typeid值不等于2或者文章id值不等于469,根据实际情况,这里可以使用多种匹配;

5.errHtml&mdash;&mdash;定义的页面展示HTML代码;

6. document.title&mdash;&mdash;标题;

隐蔽使用:

可以把js代码藏到其他js文件中,或者js加密等等。

读到这里,这篇“js怎么实现无刷新跳转404页面不存在效果”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注主机评测网行业资讯频道。


上一篇:Python中深浅拷贝的使用及注意事项是什么

下一篇:Python Casting怎么使用


Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器