Javascript : Detect when console is activated and do something about it
Problem:
You do not want your website visitors to see what is behind the curtain of your website. You want your web page to have the ability to detect whenever a user activates the browser's console(DevTools, Firebug, etc ) and do something about it. Such as redirect the user to a new page, troll the user or prompt the user not to peek behind the curtain.
Solution:
This JavaScript code is a cross browser's solution that will detect if a user activates the console or dev tool inspector. Upon detection, it will redirect the user to another page /nopeeking.php
.
window.onresize = function(){
if ((window.outerHeight - window.innerHeight) > 100) {
window.location = "/nopeeking.php"; // or whatever action you want to happen upon console activation detection.
}
}
NOTE: This is one of the methods that you can use to troll the users(crackers) that attempt to peek/temper with your web page JavaScript. Check out the JavaScript obfuscator at https://javascriptobfuscator.herokuapp.com/ as well.
Use https://javascriptobfuscator.herokuapp.com/ to inject anti-console, obfuscate your code and anti-debugger to frustrate the would-be cracker. These are a couple of ways that you can deploy to stop the cracker/reverse-engineer from debugging your web app.
See also : Javascript : Put image into Chrome browser's console
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+14.7k Golang : Find commonalities in two slices or arrays example
+34k Golang : Create x509 certificate, private and public keys
+10.4k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+8.8k Golang : Find network service name from given port and protocol
+13.7k Generate salted password with OpenSSL example
+16.2k Golang : convert string or integer to big.Int type
+55.2k Golang : Unmarshal JSON from http response
+11.4k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+19.1k Mac OSX : Homebrew and Golang
+12.6k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+6.3k Golang : Break string into a slice of characters example