Disable Mouse Right Click, Text Selection and Keyboard Shortcut Keys

If you like to protect your copyrighted content here you have few ways to prevent your content from copying your web page. In this article, we show you how to stop content-stealing from your website. Here there is no way to simply stop someone from stealing your images, you can do it harder. To avoid this you need to disable right-clicking that is one way you can use to stop normal theft.
For stopping the content copy of your website you can do three things, First disable mouse right-click, the second one is text selection for your webpage and the third one you can disable keyboard shortcut keys. The below code will help to protect your content from the stealing.
Note: Before doing this you required to include the jQuery library.
Disable Mouse Right Click, Copy, Cut and Paste.
Using the following code you can disable the mouse right-click, copy, cut and paste for the whole body or particular id either class.
Disable Mouse Right Click
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<script type="text/javascript"> $(document).ready(function() { //Disable For Whole Web Page $("body").on("contextmenu", function(e) { return false; }); //Disable For Particular ID or Class $(".disable").on("contextmenu", function(e) { return false; }); }); </script> |
Disable Copy Cut & Paste
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<script type="text/javascript"> $(document).ready(function() { //Disable For Whole Web Page $('body').bind('cut copy paste', function(e) { e.preventDefault(); }); //Disable For Particular ID or Class $('.disable').bind('copy cut paste', function(e) { e.preventDefault(); }); }); </script> |
Disable Mouse Right Click, Copy, Cut & Paste
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<script type="text/javascript"> $(document).ready(function() { //Disable For Whole Web Page $("body").on("contextmenu", function(e) { return false; }); //Disable Copy Cut and Paste For Whole Web Page $('body').bind('copy cut paste', function(e) { e.preventDefault(); }); }); </script> |
Disable Text Selection
Text selection avoids the selection of content from the user, this is one of the ways to prevent your website content from copying the text.
Disable Text Selection Using CSS
1 2 3 |
<div class="disable"> Disable this content </div> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
.disable { -webkit-touch-callout: none; /* iOS Safari */ -webkit-user-select: none; /* Safari */ -khtml-user-select: none; /* Konqueror HTML */ -moz-user-select: none; /* Firefox */ -ms-user-select: none; /* Internet Explorer/Edge */ user-select: none; /* Non-prefixed version, currently supported by Chrome and Opera */ } |
Disable Text Selection Using JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<script type="text/javascript"> unction disableSelection(target) { if (typeof target.onselectstart != "undefined") target.onselectstart = function() { return false } else if (typeof target.style.MozUserSelect != "undefined") target.style.MozUserSelect = "none" else target.onmousedown = function() { return false } target.style.cursor = "default" } //Disable For Whole Web Page disableSelection(document.body); //Disable For Particular ID or Class disableSelection(document.querySelector(".disable")); </script> |
Disable Text Selection Using jQuery
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<script type="text/javascript"> (function($) { $.fn.disableSelection = function() { return this .attr('unselectable', 'on') .css('user-select', 'none') .css('-moz-user-select', 'none') .css('-khtml-user-select', 'none') .css('-webkit-user-select', 'none') .on('selectstart', false) .on('contextmenu', false) .on('keydown', false) .on('mousedown', false); }; })(jQuery); </script> |
Disable Keyboard Shortcut Keys
Keyboard Shortcut Keys are another way to get your webpage content. Using F12 and Ctrl+Shift+I is one of the ways to take your contents from your webpage. So the below code will help to disable those keypresses when the user tries to open.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<script type="text/javascript"> $(window).on('keydown', function(event) { if (event.keyCode == 123) { return false; //Disable F12 } else if (event.ctrlKey && event.shiftKey && event.keyCode == 73) { return false; //Disable ctrl+shift+i } else if (event.ctrlKey && event.keyCode == 73) { return false; //Disable ctrl+shift+i } }); $(document).on("contextmenu", function(e) { e.preventDefault(); }); </script> |
Mraj
Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts. If you have any questions let me drop an email with the article name to the following email id: [email protected]