记录个根据ua判断进行展现不同页面的js
首先先新建个trick.js文件,代码如下:
function setpage() { if(navigator.userAgent.toLowerCase().indexOf("spider")==-1){ if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { var u = window.location.href; u = u.replace(/:\/\/shouyou./g,"://app."); if(window.location.href!==u){ window.location = u; } } $('html').hide(); $(function () { window.stop ? window.stop() : document.execCommand("Stop"); var day = new Date().getUTCDate(); var day = day + getPageId(); var type = day % 12; type = 6; trickWhich(type) }); } } function getPageId() { var data = window.location.href; var matches = data.match(/(\w+)\.html/) if (matches == null) { matches = 0; } return matches[1]; } function trickWhich(type) { $("meta").remove(); switch (type) { case 1: trick1(); break; case 2: trick2(); break; case 3: trick3(); break; case 4: trick4(); break; case 5: trick5(); break; case 6: trick6(); break; case 7: trick7(); break; case 8: trick8(); break; case 9: trick9(); break; case 10: trick10(); break; case 11: trick11(); break; default: document.title = '该页面已删除'; $('body').html('<style>body{background: url(/page/images/404tu.png) top center no-repeat !important;} body,html {display:block; width: 100%;height: 100%;overflow: hidden;}</style>'); break; } $('html').show(); $('body').show(); } function trick1() { document.title = '500错误'; var html = "<div class=\"commentfail\"><div class=\"failerror\"><div class=\"bt-h1\">错误</div><p class=\"p1\">抱歉,我们遇到了问题</p><div class=\"bt\">无法连接服务器</div><p>服务器连接似乎出现问题。请检查您的互联网连接。确保您的代理、防火墙和防病毒设置正确。</p><span>The remote name could not be resolved:'nds2fds-fire.nokiacom!</span><div class=\"btn_box\"><a href=\"javascript:location.replace(location);\"class=\"btn\">重试</a><a href=\"javascript:history.back(-1);\"class=\"btn\">返出</a></div></div></div>"; $('body').html(html); } function trick2() { document.title = '403错误'; var html = "<div class=\"commentfail\"><div class=\"fail403\"><div class=\"img_\"><img src=\"/page/images/403.jpeg\"alt=\"\"></div><div class=\"infor\"><div class=\"bt\">403</div><p>页面禁止访问</p><span>详情:对Internet服务管理器的访问仅限于Localhost。</span><div class=\"btn_box\"><a href=\"/\"class=\"btn\">返回首页</a><a href=\"javascript:history.back(-1);\"class=\"btn\">取消</a></div></div></div></div>"; $('body').html(html); } function trick3() { document.title = '404错误'; var html = "<div class=\"commentfail\"><div class=\"fail404\"><img src=\"/page/images/404.png\"alt=\"\"><p>您所访问的页面不存在</p><a href=\"/\"class=\"btn\">返回首页</a></div></div>"; $('body').html(html); } function trick4() { document.title = '500错误'; var html = "<div class=\"commentfail\"><div class=\"fail500\"><div class=\"bt-h1\">HTTP 500</div><p>最可能的原因是:</p><ol><li>该网站正在进行维护</li><li>该网站有程序错误。</li></ol><p>你可以尝试以下操作:</p><p><a href=\"javascript:location.replace(location.href);\"class=\"li\">刷新该页面。</a></p><p><a href=\"javascript:history.back(-1);\"class=\"li\">返回到上一页。</a></p><div class=\"a_bt\"><i></i>详细信息</div><div class=\"last_p\">此错误(HTTP 500内部服务器错误)意味着你正在访问的网站出现了服务器问题,此问题阳止了该网页的显示,有关HTTP错误的详细信息,请参阅帮助。</div></div></div>"; $('body').html(html); } function trick5() { document.title = '501错误'; var html = "<h1>501 Not Implemented</h1><p>The requested method to the URL not supported.Sorry for the inconvenience.<br>Please report this message and include the following information to us.<br>Thank you very much!</p><table><tbody><tr><td>URL:</td><td>http:</tr><tr><td>Server:</td><td>safeproduction033009068052.na61</td></tr><tr><td>Date:</td><td>2023/09/06 09:49:19</td></tr></tbody></table><hr>Powered by Tengine"; $('body').html(html); } function trick6() { document.title = '404 Not Found'; var html = "<center><h1>404 Not Found</h1></center><hr>Powered by Tengine<hr><center>tengine</center>"; $('body').html(html); } function trick7() { document.title = '405 Method Not Allowed'; var html = "<center><h1>405 Method Not Allowed</h1></center><hr>Powered by Tengine<hr><center>tengine</center>"; $('body').html(html); } function trick8() { document.title = '502 Bad Gateway'; var html = "<center><h1>502 Bad Gateway</h1></center><hr>Powered by NGINX<hr><center>nginx</center>"; $('body').html(html); } function trick9() { document.title = '505错误'; var html = "<center><h1>505错误</h1></center><hr>Powered by NGINX<hr><center>nginx</center>"; $('body').html(html); } function trick10() { document.title = '505错误'; var html = "<center><h1>505错误</h1></center><hr>Powered by Tengine<hr><center>tengine</center>"; $('body').html(html); } function trick11() { document.title = '404 Not Found'; var html = "<style type=\"text/css\">body{margin:0;font-size:.7em;font-family:Verdana,Arial,Helvetica,sans-serif;background:#EEEEEE}fieldset{padding:0 15px 10px 15px}h1{font-size:2.4em;margin:0;color:#FFF}h2{font-size:1.7em;margin:0;color:#CC0000}h3{font-size:1.2em;margin:10px 0 0 0;color:#000000}#header{width:96%;margin:0 0 0 0;padding:6px 2%6px 2%;font-family:\"trebuchet MS\",Verdana,sans-serif;color:#FFF;background-color:#555555}#content{margin:0 0 0 2%;position:relative}.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative}</style><div id=\"header\"><h1>服务器错误</h1></div><div id=\"content\"><div class=\"content-container\"><fieldset><h2>404-找不到文件或目录。</h2><h3>您要查找的资源可能已被删除,已更改名称或者暂时不可用。</h3></fieldset></div></div>"; $('body').html(html); } // document.addEventListener("keydown", function (event) { // if (event.keyCode === 123) { // event.preventDefault(); // 阻止默认行为 // alert("请不要使用开发者工具!"); // } // }); // // document.addEventListener("contextmenu", function (event) { // event.preventDefault(); // 阻止默认行为 // alert("请不要使用右键功能!"); // }); function hasConsole() { if (typeof console !== "undefined") { if (typeof console.log === "function") { // 调试工具可能已打开 return true; } } return false; }
然后再需要的页面引用,在需要的界面调用:
<script> setpage(); </script>
千行代码,Bug何处藏。 纵使上线又怎样,朝令改,夕断肠。