js how to prohibit page copy and right click

1. Disable the right button and copy 
Method 1: 
Add the following code to the web page: 
copy code code show as below:

<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"> 
Essential Above, 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. Make the menu "File" - "Save As" Invalidation 
If only right-clicking and selecting copy are prohibited, others can copy the file through "File" - "Save As" in the browser menu. To make the 

copy  invalid, add the following code between <body> and </body>:
copy code code show as below:

<noscript> 
<iframe src="*.htm"></iframe> 
</noscript> 

In this way, when the user saves the web page, the error "Cannot save the web page" occurs. 

In addition, you can also use the event.preventDefault() method to prevent oncontextmenu() and onselectstart() 
copy code code show as below:

document.oncontextmenu=function(evt){ 
possibly.preventDefault(); 


document.onselectstart=function(evt){ 
possibly.preventDefault(); 


Since it can be disabled, of course, it can also be enabled, and the event can be reassigned, which can be assigned to null, or a string or a boolean value. Such as: 
copy code code show as below:

document.oncontextmenu=""; 
document.onselectstart=true; 

Or disable js: Open Google Chrome, select "Settings" - select "Privacy Settings" - option "Content Settings" - select "JavaScript" - select "Do not allow any website to run JavaScript", and refresh the settings.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325727349&siteId=291194637