The website content cannot be copied, pasted, or saved as JavaScript code.

Source: Internet
Author: User

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.

 

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.