Created
November 19, 2014 06:46
-
-
Save hiwanz/4157a001c7079c218c3a to your computer and use it in GitHub Desktop.
Detect if browser console is opened.(Chrome 38.0.2125.111 m,IE 11 is tested)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>console track</title> | |
</head> | |
<body> | |
console status: <span id="stat"></span> | |
<script> | |
function isConsoleOpen() { | |
var el = document.createElement('div'); | |
var ret = false; | |
el.__defineGetter__('id', function() {ret = true}); | |
console.log(el); | |
console.clear(); | |
return ret; | |
} | |
// test | |
setInterval(function() { | |
stat.innerHTML = isConsoleOpen() ? 'open' : 'closed'; | |
}, 1000); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment