This article mainly introduces how to disable debugging on the JavaScript console. For more information, see several giant companies, Facebook and Netflix, and decide to prohibit users from executing JavaScript commands on the console.
This was initially started with Facebook, which was used to prevent malicious users from spreading messages (sending a large amount of junk information to all Facebook users) by executing specific commands on the JavaScript console ).
Of course, this is a lot of criticism, but before I participate, the code they use is as follows:
The Code is as follows:
// It seems Netflix is the only Facebook player. [https://news.ycombinator.com/item? The id = 7222129].
(Function (){
Try {
Var $ _ console $ = console;
Object. defineProperty (window, "console ",{
Get: function (){
If ($ _ console $. _ commandLineAPI)
Throw "sorry, this website has disabled the console Script Function for user security ";
Return $ _ console $
},
Set: function ($ val $ ){
$ _ Console $ = $ val $
}
})
} Catch ($ ignore $ ){
}
})();
Although I speak a little bit, I actually think this is legal. From their perspective, if temporarily disabling the console helps prevent a problem, you have to do so.
But in the long run, this is really not a good idea; its goal may be to block the target users that depend on them.
In any case, if you want to prevent the console from executing scripts, this code looks good and does.