Reputation: 251
$(document).bind("contextmenu",function(e) {
e.preventDefault();
});`
I try this code but only disable the right click and inspect element option but will allow f12 and directly take inspect element from browser
how to slove it ... thanks
Upvotes: 1
Views: 2568
Reputation: 21
You can try this piece of code, actually it does not hide elements but it detects whether the inspect menu is opened or not. if it's opened the elements will be hidden and the user will be redirected away from your site (Note: you can comment the redirect line if you want), even on returning back he will found that your code which is inside the body is hidden, and also the elements on the inspect menu will be hidden until he closes the inspect menu.
Code
<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>
Clarification
To disable mouse clicks and F12
and CTRL + 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>
Detect if inspect menu is opened
<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>
And one important thing left.. Even on going to the browser menu ► more tools ► developer tools.. The code executes its tasks in the correct way, and make sure to add it in the beginning of your body
Note: some lines are not mine
Upvotes: 1
Reputation: 710
This is definitely not possible to do from a web page.
Even if you disable right click and disable the default behaviors for F12, Ctrl+Shift+I, and Ctrl+Shift+J, there is no way to stop a user from opening Dev Tools on a different page and navigating to your page with Dev Tools already open.
Also, you can access Dev Tools by going to Menu > Tools > Developer tools, which cannot be prevented by any website.
Upvotes: 1
Reputation: 86
You simply can't.
Code inspectors are designed for debugging HTML and Javascript. They do so by showing the live DOM object of the web page. That means it reveals HTML code of everything you see on the page, even if they're generated by Javascript. Some inspectors even shows the code inside iframes.
they are browser tools may be any visitors have installed a custom addon or plugin like firebug or anything else, you can not disable this by your Code
You can disable the source from inspect element can be opened like right click
document.addEventListener('contextmenu', function(e) {
e.preventDefault();
});
or by Disabling the Key
$(document).keydown(function(e){
if(e.which === 123){
return false;
}
});
The function key F12 which directly take inspect element from browser.
Upvotes: 1