目前比较流行的屏蔽PC电脑版的JS代码

效果图:

eae00153e5ea40128d200ef3290207cd.png


1.JS代码,加入网站头部head文件,就是全站屏蔽

创建一个JS文件,添加下面代码


var a=document.body.innerHTML;

document.body.innerHTML=a.replace(/\ufeff/g,'');

 

    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='/close.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:100%;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;

    }

}

 

    'jQuery';




2.自己网站根目录添加/close.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>

*{margin:0;padding:0}body,html{width:100%;height:100%;overflow:hidden;font-family:Helvetica,Arial,Microsoft Yahei,sans-serif;background-image:url(back.jpg);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>

<script type="text/javascript"> document.body.oncontextmenu=document.body.ondragstart= document.body.onselectstart=document.body.onbeforecopy=function(){return false;};

document.body.onselect=document.body.oncopy=document.body.onmouseup=function(){document.selection.empty();}; </script>

<script type="text/javascript">   

document.onkeydown=function(){

var e = window.event||arguments[0];

if(e.keyCode==123){

return false;

}

if((e.ctrlKey)&&(e.shiftKey)&&(e.keyCode==73)){

return false;

}

if((e.ctrlKey)&&(e.keyCode==85)){

return false;

}

if((e.ctrlKey)&&(e.keyCode==83)){

  

   return false;

}

}

document.oncontextmenu=function(){

return false;

}

var threshold = 160;

window.setInterval(function() {  

    if (window.outerWidth - window.innerWidth > threshold ||   

    window.outerHeight - window.innerHeight > threshold) {  

function disableDebugger() {

debugger;

}

$(document).ready(function () {

disableDebugger();

});

    }  

}, 1e3);  

</script>

<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>Copyright 2023 cit168.com Inc.

<div id="tongji" style="display: none;">

<script>document.getElementById("tongji").style.display="none"</script>

</div>


</div></body></html>


上面代码的图片,可以不要


版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论