Several ways to disable the right mouse click in the Web page

Source: Internet
Author: User

Here we mainly introduce two methods, one is to use JS to handle, and the other is set in the HTML attribute.

Method One: JS

1:

<script language= "javascript" >document.onmousedown=disableclick;status= "right click Disabled"; Function Disableclick (event) {  if (event.button==2)   {     alert (status);     return false;       }} </script>


2:

Document.addeventlistener ("ContextMenu", function (e) {    e.preventdefault ();}, False);


3: Using jquery

$ (document). On ({    "ContextMenu": function (e) {        console.log ("ctx menu button:", E.which);         Stop the context menu        e.preventdefault ();    },    "MouseDown": function (e) {         console.log ("Normal mouse Down: ", E.which);     },    " MouseUp ": function (e) {         console.log (" Normal mouse Up: ", E.which);}     );
Or:

$ (document). Ready (function () {            Document.oncontextmenu = Document.body.oncontextmenu = function () {return false;}        });




Method Two: HTML property settings

<body oncontextmenu= "return false" >...</body>

Finally: Try not to do so unless special use.

Preference:http://stackoverflow.com/questions/737022/how-do-i-disable-right-click-on-my-web-page

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.