1. Invalidate right click and copy
Method 1:
Add the following code to the web page:
The code copy is as follows:
<script language="Javascript">
document.oncontextmenu=new Function("event.returnValue=false");
document.onselectstart=new Function("event.returnValue=false");
</script>
Method 2:
Add the following code to <body>:
<body oncontextmenu="return false" onselectstart="return false">
or
<body oncontextmenu="event.returnValue=false" onselectstart="event.returnValue=false">
In essence, method 2 is the same as method 1.
Method 3:
If you only restrict copying, you can add the following code to <body>:
<body oncopy="alert('Sorry, copying is prohibited!');return false;">
2. Invalid menu "File" - "Save As"
If you just prohibit right-clicking and selecting copying, others can also copy files through "File" - "Save As" in the browser menu. To make the copy
If Bei is invalid, you can add the following code between <body> and </body>:
The code copy is as follows:
<noscript>
<iframe src="*.htm"></iframe>
</noscript>
In this way, when the user saves a web page, the error "Cannot save the web page" will appear.
In addition, you can also use the event.preventDefault() method to block oncontextmenu() and onselectstart().
The code copy is as follows:
document.oncontextmenu=function(evt){
evt.preventDefault();
}
document.onselectstart=function(evt){
evt.preventDefault();
};
Since it can be disabled, of course it can also be enabled, just reassign the event, you can assign it to null, or both string and boolean. like:
The code copy is as follows:
document.oncontextmenu="";
document.onselectstart=true;
Or disable js: Open Google Chrome, select "Settings" Select "Privacy Settings" Option "Content Settings" Select "JavaScript" Select "Don't allow any website to run JavaScript", and the settings are refreshed.