The javascript implementation prohibits copying web content

  • 2020-05-05 10:57:53
  • OfStack

Take a note


// Disable right-click menu, copy, 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 up the CSS Disable selection (if written below CSS No need for this code, new browser support)
$(function() {
    $("body").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 invalidations after disabling JavaScript, write in CSS (new browser support, and increasingly standard) :


body {
    -moz-user-select:none;  /* Firefox Private property */
    -webkit-user-select:none;  /* WebKit Kernel private properties */
    -ms-user-select:none;  /* IE Private property (IE10 And after ) */
    -khtml-user-select:none;  /* KHTML Kernel private properties */
    -o-user-select:none;  /* Opera Private property */
    user-select:none;  /* CSS3 attribute */
}

The code is very simple, but the functionality is very practical, but it is important to note that in this free Internet actually do not prohibit copying is very worthy of promotion, we use it as the case.


Related articles: