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

发布时间:2023-05-06 15:35:53 作者:iii
来源:亿速云 阅读:253

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

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><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><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 h2{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)实现无刷新跳转404页面不存在效果</div>
</body>
</html>

代码讲解:

1. https://apps.bdimg.com/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页面不存在效果”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. web浏览器中的地理空间数据可视化
  2. Visual Studio 11增强HTML5和JS的支持

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

js

上一篇:Golang异常控制处理程序错误流程是什么

下一篇:前端的包管理器npm/pnpm等怎么使用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》