The website content cannot be copied, pasted, or saved as JavaScript code.
This article mainly introduces how to implement JavaScript to prohibit copying, pasting, and saving the website content. For more information, see
1. Disable right-click and copy
Method 1:
Add the following code to the webpage:
The Code 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 replication, you can add the following code in <body>:
<Body oncopy = "alert ('Sorry, copying is prohibited! '); Return false; ">
2. invalidate the menu "file"-"Save"
If you only disable right-click and select copy, you can also use "file"-"Save as" in the browser menu to copy files. To copy
Bay failure. You can add the following code between <body> and </body>:
The Code is as follows:
<Noscript>
<Iframe src = "*. htm"> </iframe>
</Noscript>
In this way, when a user saves a webpage, the error "the Web page cannot be saved" will occur.
You can also use the event. preventDefault () method to prevent oncontextmenu () and onselectstart ()
The Code is as follows:
Document. oncontextmenu = function (evt ){
Evt. preventDefault ();
}
Document. onselectstart = function (evt ){
Evt. preventDefault ();
};
Since it can be disabled, you can also enable it and assign a value to the event again. You can assign a value to null or a string or Boolean value. For example:
The Code is as follows:
Document. oncontextmenu = "";
Document. onselectstart = true;
Or disable js: Open Google's browser, select "Settings", select "privacy settings", select "content settings", select "JavaScript", and select "do not allow any website to run JavaScript ", refresh the settings.