Original article: Disable the User's JavaScript Console
Original Article Date: January 1, March 06, 2014
Translated on: February 1, March 07, 2014
Translated by: Tie
Several giant companies, Facebook and Netflix, have decided 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:
// 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.