Disable Web page Right-click menu and mouse drag selected statement
First, disable the right mouse button menu:
There are two ways to disable the right mouse button
1. Add the JavaScript event handle to the body tag of the HTML element, with the following code:
<body oncontextmenu= "return false" >
Note: You can also disable the right button in the location specified in the webpage, for example, you just want to disable the right-click on a picture on a webpage, or you just want to disable the right-click on a text or table in a webpage, and you just add the red code as above to the corresponding HTML tag element, for example:
<!--added to the picture--
<table oncontextmenu= "return false" >
<!--added to the table--
<font oncontextmenu= "return false" > text content </font>
<!--added to text--
2, write a JavaScript function, and then invoke the event processing, the code is as follows:
<script language=javascript>
<!--
Document.oncontextmenu=mylock1;
function Mylock1 () {
Event.returnvalue=false;
}
-
</script>
Description: Please note that the code is case-sensitive! Copy the above code to the Web page HTML source code
If you want to right-click on the label specified by the page element, simply change the document to the corresponding Page object tag name.
Second, prohibit drag to select the page elements:
As in the previous example, there are two ways to disable the right mouse button
1. Add the JavaScript event handle to the body tag of the HTML element, with the following code:
<body onselectstart= "return false" >
Description: Similar to the above forbidden right-click usage
2, write a JavaScript function, and then invoke the event processing, the code is as follows:
<script language=javascript>
<!--
Document.onselectstart=mylock1;
function Mylock1 () {
Event.returnvalue=false;
}
-
</script>
Description: Please note the case of the statement! Copy the above code to the Web page HTML source code If you want to right-click on the label specified by the page element, simply change the document to the corresponding Page object tag name.
To sum up, if we both prohibit the page right-click menu, but also disable the mouse drag, that can be used in the following two ways:
Method One:
<body oncontextmenu= "return false;" onselectstart= "return false" >
Method Two:
<script language=javascript>
<!--
Document.onselectstart=mylock1;
Document.oncontextmenu=mylock1;
function Mylock1 () {
Event.returnvalue=false;
}
-
</script>
Disable Web page Right-click menu and Mouse Drag selection