Javascript allows you to Disable copying, pasting, and saving website content

Source: Internet
Author: User

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

<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.
Fang

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. Enable menu "TextInvalid part "-" 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>:
<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 ()

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:

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.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.