目前比较流行的屏蔽PC电脑版的JS代码
1、在需要屏蔽的页面加入JS
<script type="text/javascript" language="javascript" src="pingbipc.js"></script>
2、pingbipc.js代码如下:
var system = { win: false, mac: false, xll: false }; var p = navigator.platform; var us = navigator.userAgent.toLowerCase(); system.win = p.indexOf("Win") == 0; system.mac = p.indexOf("Mac") == 0; system.x11 = (p == "X11") || (p.indexOf("Linux") == 0); if (system.win || system.mac || system.xll) { var iframe_url = '/wg.html'; $("head").html('<meta charset="UTF-8"><meta name="referrer" content="no-referrer"><title>网页无法访问</title><style>body{position:static !important;}body *{ visibility:hidden; }</style> '); $("body").empty(); $(document).ready(function() { $("body").html('<iframe style="width:100%; height:460px;position:absolute;margin-left:0px;margin-top:0px;top:0%;left:0%;" id="mainFrame" src="' + iframe_url + '" frameborder="0" scrolling="no"></iframe>').show(); $("body *").css("visibility", "visible"); }); } document.oncontextmenu = function(e) { var e = e || window.event; e.returnValue = false; return false; } window.onkeydown = function(e) { if (e.ctrlKey && e.keyCode == 83) { alert('禁止使用ctrl+s'); e.preventDefault(); e.returnValue = false; return false; } }
3、wg.html代码如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>内容审查整改中</title> <meta name="viewport" content="initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <style type="text/css"> * { margin:0; padding:0 } body,html { width:100%; height:100%; overflow:hidden; font-family:Helvetica,Arial,Microsoft Yahei,sans-serif; background-image:url('https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png'); background-color:#354141; background-repeat:repeat; background-size:cover; font-size:14px; position:fixed; text-shadow:1px 1px rgba(0,0,0,.3) } h2 { color:#fff; font-size:28px; font-weight:400; text-transform:capitalize; margin:0 0 30px } li { display:inline-block; font-size:42px; font-weight:400; text-align:center; height:100px; text-shadow:none; vertical-align:middle; color:#fff; margin:10px 0; height:auto; padding-bottom:15px; background:0 0; width:136px; border-right:2px dashed rgba(255,255,255,.26) } li:last-child { border:none } li span { line-height:70px } li div { display:block; font-size:16px; margin-top:0; text-align:center; background:rgba(255,255,255,.06); color:#fff; padding:0; height:45px; line-height:45px } .fed-main-info { width:90%; min-width:320px; position:absolute; top:50%; left:50%; color:#fff; font-size:16px; text-align:center; transform:translate(-50%,-50%); z-index:999; padding-bottom:80px } .fed-foot-info { position:fixed; text-align:center; width:100%; bottom:40px; color:#eee } @media (max-width:768px) { .fed-main-info { width:320px } li:nth-last-child(3) { border:none } .fed-foot-info { bottom:20px } } </style> </head> <body> <div class="fed-main-info"> <h2>非常抱歉,禁止访问!全站内容审核中...</h2>为了更加合法合规运营网站,我们正在对全站内容进行审核,之前的内容审核通过后才能访问。</div> <div class="fed-foot-info"> <script type="text/javascript">document.write('Copyright ' + new Date().getFullYear() + ' ' + location.hostname + ' Inc.');</script></div> </body> </html>
- 支付宝
- 微信