Javascript: prohibit copying webpage content _ javascript skills

Source: Internet
Author: User
This article describes how to prohibit the copying of webpage content using javascript. if you need it, take a note.

The code is as follows:


// Disable right-click menu, copy, and select
$ (Document). bind ("contextmenu copy selectstart", function (){
Return false;
});
// Disable Ctrl + C and Ctrl + V (supported by all browsers)
$ (Document). keydown (function (e ){
If (e. ctrlKey & (e. keyCode = 65 | e. keyCode = 67 )){
Return false;
}
});
// Set CSS to prohibit selection (this code is not required if the following CSS is written, which is supported by the new browser)
$ (Function (){
$ ("Body" detail .css ({
"-Moz-user-select": "none ",
"-Webkit-user-select": "none ",
"-Ms-user-select": "none ",
"-Khtml-user-select": "none ",
"-O-user-select": "none ",
"User-select": "none"
});
});

To prevent invalid JavaScript code after it is disabled, you can write it in CSS (supported by the new browser and gradually becomes a standard ):

The code is as follows:


Body {
-Moz-user-select: none;/* Firefox Private attribute */
-Webkit-user-select: none;/* Private attributes of the WebKit kernel */
-Ms-user-select: none;/* Private IE attributes (IE10 and later )*/
-Khtml-user-select: none;/* private attribute of the KHTML kernel */
-O-user-select: none;/* Opera private attribute */
User-select: none;/* CSS3 attribute */
}

The code is very simple, but the implementation function is very practical, but it should be noted that in this free internet, it is not worth promoting to prohibit replication. it is practical for everyone.

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.