Hi mọi người.
Disable copy content, Hạn chế sao chép nội dung là cần thiết với một website. Nó không chống lại được các đối tượng sao chép có chuyên môn về công nghệ thông tin, nhưng với các đối tượng copy thông thường thì rất hữu hiệu.
-
Thực hiện cách 1
Sử dụng kết hợp cả Jquery và Css để hạn chế sao chép nội dung. Đoạn code nhỏ dưới đây phải được sao chép vào file js và css của themes. hãy sử dụng nó vào child themes.
123456789/* Css prevent blacked out text on the site */body{-webkit-touch-callout: none;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;-o-user-select: none;user-select: none;}Thêm code Jquery để disable copy content với khả năng ngăn chặn bôi đen, chặn chuột phải, chặn F12, chặn Ctrl I, chặn Ctrl J, chặn Ctrl U, chặn Ctrl S trên macOS
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253// Disable copy content, prevent blacked out text, prevent "I" key, "J" key, "S" key + macOS, "U" key, "F12" keyjQuery(document).ready(function(){jQuery(function() {jQuery(this).bind("contextmenu", function(event) {event.preventDefault();alert('Right click disable in this site! Chuột phải đã được vô hiệu hóa trên site này !')});});(function() {'use strict';let style = document.createElement('style');style.innerHTML = '*{ user-select: none !important; }';document.body.appendChild(style);})();window.onload = function () {document.addEventListener("contextmenu", function (e) {e.preventDefault();}, false);document.addEventListener("keydown", function (e) {if (e.ctrlKey && e.shiftKey && e.keyCode == 73) {disabledEvent(e);}if (e.ctrlKey && e.shiftKey && e.keyCode == 74) {disabledEvent(e);}if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {disabledEvent(e);}if (e.ctrlKey && e.keyCode == 85) {disabledEvent(e);}if (event.keyCode == 123) {disabledEvent(e);}}, false);function disabledEvent(e) {if (e.stopPropagation) {e.stopPropagation();} else if (window.event) {window.event.cancelBubble = true;}e.preventDefault();return false;}}}); -
Thực hiện cách 2
Tạo 2 file và folder /assets/js/main.js và /assets/css/main.css nằm trong child theme. Sao chép toàn bộ Css và Js pate chúng vào. Copy code dưới đây pate vào file function.php
1234567// Enqueue required fonts, scripts, and styles.add_action( 'wp_enqueue_scripts', 'favorite_enqueue_scripts' );function favorite_enqueue_scripts() {wp_enqueue_script( 'wph_mainjs', get_stylesheet_directory_uri() . '/assets/js/main.js' , 'jquery' , '' , true );wp_enqueue_style( 'wph_maincss', get_stylesheet_directory_uri() . '/assets/css/main.css' );}
Như vậy các bạn đã có thể ngăn chặn việc sao chép nội dung một các phi pháp từ những người dùng thông thường.
Tôi hy vọng bạn tìm thấy hướng dẫn này hữu ích. Nếu vậy, hãy xem xét chia sẻ nó với khán giả của bạn!
Nguồn: longvietweb[.]com










