Home > Web Front-end > JS Tutorial > Website content is prohibited from copying, pasting, and saving as js code_javascript skills

Website content is prohibited from copying, pasting, and saving as js code_javascript skills

WBOY
Release: 2016-05-16 16:58:04
Original
1741 people have browsed it

1. Disable right-click and copy
Method 1:
Add the following code to the web page:

Copy code Code As follows:



Method 2:
Add the following code to :

or

Essentially, method 2 It is the same as method 1.

Method 3:
If you only limit copying, you can add the following code to :


2. Disable "File" - "Save As" in the menu
If you just disable right-clicking and selecting copy, others can also use "File" - "Save As" in the browser menu "Copy the file. In order to invalidate the copy

, you can add the following code between and :
Copy code The code is as follows:



In this way, when the user saves the web page, the error "Unable to save the web page" will appear.

In addition, you can also use the event.preventDefault() method to prevent oncontextmenu() and onselectstart()
Copy code The code is as follows:

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

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

Since it can be prohibited, of course you can also enable it and reassign the event to null or character. Both string and Boolean values ​​are acceptable. For example:
Copy code The code 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 "Do not allow Any website runs JavaScript" and the settings are refreshed.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template