1. Prohibit the right mouse button menu:
There are two ways to prohibit the right mouse button
1. Add a Javascript event handle to the Body tag of the HTML element, the code is as follows:
The code copy is as follows:
<body onContextMenu="return false">
Note: You can also prohibit right-clicking at the specified location of the web page. For example, you only want to prohibit right-clicking on a certain image in the web page to prevent downloading, or you only want to prohibit right-clicking on a paragraph of text or table in the web page. You only need to add the above red code to the corresponding HTML tag element, for example:
The code copy is as follows:
<img src="logo.gif" width=88 height=31 onContextMenu="return false">
<!--Added to the picture-->
<table onContextMenu="return false">
<!--Added in the table-->
<font onContextMenu="return false">Text content</font>
<!--Added to the text-->
2. Write a Javascript function and then call event processing. The code is as follows:
The code copy is as follows:
<script language=javascript>
<!--
document.oncontextmenu=mylock1;
function mylock1(){
event.returnValue=false;
}
//-->
</script>
Note: Please pay attention to the code case! Just copy the above code between <head> and </head> of the web page HTML source code.
If you want to right-click the tag specified by the web page element, just change the document to the corresponding web page object tag name.
2. Disable dragging and selecting web page elements:
As with the above example, there are two methods to prohibit the right mouse button.
1. Add a Javascript event handle to the Body tag of the HTML element, the code is as follows:
The code copy is as follows:
<body onSelectStart="return false">
Note: Similar to the usage of right-click above
2. Write a Javascript function and then call event processing. The code is as follows:
The code copy is as follows:
<script language=javascript>
<!--
document.onselectstart=mylock1;
function mylock1(){
event.returnValue=false;
}
//-->
</script>
Note: Please pay attention to the upper and lower case of the statement! Just copy the above code between <head> and </head> of the web page HTML source code.
If you want to right-click the tag specified by the web page element, just change the document to the corresponding web page object tag name.
To sum up, if we want to prohibit the right-click menu of the web page and the mouse drag, we can use the following two methods:
Method 1:
The code copy is as follows:
<body onContextMenu="return false;" onSelectStart="return false">
Method 2:
The code copy is as follows:
<script language=javascript>
<!--
document.onselectstart=mylock1;
document.oncontextmenu=mylock1;
function mylock1(){
event.returnValue=false;
}
//-->
</script>
The above are a summary of my commonly used methods. It is not very comprehensive. If you have other methods, please leave me a message. This article continues to be updated.