How to disable JavaScript console debugging _ javascript skills

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.