在php中隐藏Inspect元素

时间:2016-04-20 11:00:17

标签: javascript php

 $(document).bind("contextmenu",function(e) {
 e.preventDefault();
});`

我尝试使用此代码,但只禁用右键单击并检查元素选项但允许使用f12并直接从浏览器中获取inspect元素

如何解决它...... 感谢

3 个答案:

答案 0 :(得分:1)

你根本无法做到。

代码检查器专为调试HTML和Javascript而设计。他们通过显示网页的实时DOM对象来实现。这意味着它会显示您在页面上看到的所有内容的HTML代码,即使它们是由Javascript生成的。一些检查员甚至在iframe中显示代码。

他们是浏览器工具可能是任何访问者都安装了自定义插件或插件,如firebug或其他任何东西,你不能通过你的代码禁用它

您可以通过右键单击

来禁用来自inspect元素的源
document.addEventListener('contextmenu', function(e) {
  e.preventDefault();
});

或通过禁用密钥

$(document).keydown(function(e){
    if(e.which === 123){
       return false;
    }
});

直接从浏览器中获取检查元素的功能键F12。

答案 1 :(得分:1)

这绝对不可能通过网页进行。

即使您禁用右键单击并禁用F12,Ctrl + Shift + I和Ctrl + Shift + J的默认行为,也无法阻止用户在其他页面上打开Dev Tools并导航到您的已经打开Dev Tools的页面。

此外,您可以转到菜单>访问开发工具。工具>开发人员工具,任何网站都无法阻止。

答案 2 :(得分:1)

您可以尝试这段代码,实际上它不会隐藏元素,但是会检测是否打开了检查菜单。如果已打开,则元素将被隐藏,并且用户将被重定向到您的站点之外。注意:,如果需要,您可以注释重定向行),即使返回他会发现您体内的代码已被隐藏,并且检查菜单上的元素也将被隐藏,直到他关闭检查菜单。

代码

    <body oncontextmenu="return false" onkeydown="return false;" onmousedown="return false;">
       <script>
         $(document).bind("contextmenu",function(e) {
            e.preventDefault();
         });
                        
         eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(3(){(3 a(){8{(3 b(2){7((\'\'+(2/2)).6!==1||2%5===0){(3(){}).9(\'4\')()}c{4}b(++2)})(0)}d(e){g(a,f)}})()})();',17,17,'||i|function|debugger|20|length|if|try|constructor|||else|catch||5000|setTimeout'.split('|'),0,{}))
        </script>
                    
         <script type="text/javascript">
             var element = new Image;
             var devtoolsOpen = false;
             element.__defineGetter__("id", function() {
                devtoolsOpen = true; // This only executes when devtools is open.
                window.location.replace ("http://www.NoSource.com");
                document.getElementsByTagName("BODY")[0].style.display = "none";
             });
             
             setInterval(function() {
                devtoolsOpen = false;
                console.log(element);
                document.getElementById('output').innerHTML += (devtoolsOpen ? "dev tools is open\n" : "dev tools is closed\n");
             }, 1000);
          </script>
    </body>

澄清

禁用鼠标单击以及F12CTRL + SHIFT + I

    <body oncontextmenu="return false" onkeydown="return false;" onmousedown="return false;">
       <script>
         $(document).bind("contextmenu",function(e) {
            e.preventDefault();
         });
                        
         eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(3(){(3 a(){8{(3 b(2){7((\'\'+(2/2)).6!==1||2%5===0){(3(){}).9(\'4\')()}c{4}b(++2)})(0)}d(e){g(a,f)}})()})();',17,17,'||i|function|debugger|20|length|if|try|constructor|||else|catch||5000|setTimeout'.split('|'),0,{}))
        </script>

检测是否打开检查菜单

 <script type="text/javascript">
     var element = new Image;
     var devtoolsOpen = false;
     element.__defineGetter__("id", function() {
        devtoolsOpen = true; // This only executes when devtools is open.
        window.location.replace ("http://www.NoSource.com");
        document.getElementsByTagName("BODY")[0].style.display = "none";
     });

     setInterval(function() {
        devtoolsOpen = false;
        console.log(element);
        document.getElementById('output').innerHTML += (devtoolsOpen ? "dev tools is open\n" : "dev tools is closed\n");
     }, 1000);
  </script>

还有一件重要的事情。即使进入浏览器菜单,►更多工具►开发人员工具。代码以正确的方式执行其任务,并确保将其添加到身体的开始

注意:有些行不是我的

相关问题