How To Disable cut, Copy Paste And Mouse Right Click in blogger and websites

How To Disable Copy Paste And Mouse Right Click Using JavaScript, CSS, jQuery, Swift

  • Any new website must have original material. Search engines rank your website not simply on the basis of backlinks or social media shares, but also on how unique and beneficial your material is to the audience, which is decided by the number of visitors to a certain piece.
Disable cut, Copy Paste And Mouse Right Click
  • However, not everyone thinks this way; there will always be a portion of people who only know how to copy and paste content. 
  • The worst-case scenario is that their posts rank higher in search engine results than the original content. 
  • I understand how irritating this can be, especially when bloggers like me and you spend a lot of time creating blogs from the ground up and a tiny percentage simply copies and pastes the information onto their own.
  1. One method is by using JavaScript which disables copy-paste for your whole website and the other one uses CSS, which can also be used to enable copy-paste for some part of your posts.
  2. Another one is by disabling mouse right-click and disabling copy paste using jQuery.
  • You should be aware that these methods are not foolproof; any competent user may disable JavaScript or delete CSS, but our goal is to stop the bulk of those individuals; you cannot, in any event, block all of them. So, without further ado, let me teach you how to use JavaScript, CSS, and/or jQuery to disable copy-paste on your website.
  • Because I believe WordPress plugins already exist for this purpose, I'll confine my instructions to Blogger users. However, you can simply utilize these on your website by editing the *.css of the header or template. Please feel free to ask any specific questions in the comment box at the bottom of this page.


Disable Right Mouse Click Using jQuery:


1
2
3
4
5
6
7
8
9
10
11
12
13
<script type="text/javascript">
$(document).ready(function () {
    //Disable full page
    $("body").on("contextmenu",function(e){
        return false;
    });
     
    //Disable part of page
    $("#id").on("contextmenu",function(e){
        return false;
    });
});
</script>

Disable Cut, Copy, Paste Using jQuery:


1
2
3
4
5
6
7
8
9
10
11
12
13
<script type="text/javascript">
$(document).ready(function () {
    //Disable full page
    $('body').bind('cut copy paste', function (e) {
        e.preventDefault();
    });
     
    //Disable part of page
    $('#id').bind('cut copy paste', function (e) {
        e.preventDefault();
    });
});
</script>

Disable Right Mouse Click & Cut, Copy, Paste Using jQuery:


1
2
3
4
5
6
7
8
9
10
11
12
13
<script type="text/javascript">
$(document).ready(function () {
    //Disable cut copy paste
    $('body').bind('cut copy paste', function (e) {
        e.preventDefault();
    });
    
    //Disable mouse right click
    $("body").on("contextmenu",function(e){
        return false;
    });
});
</script>
  • The #id is used in the above three scripts to block copy paste on a specific region of a page. Only use this if you want to disable a specific portion; otherwise, just use the first part of the code, which contains $("body"), to prevent copy paste for the entire page.

Disable Copy Paste Using JavaScript:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!--Disable Copy Paste www.codingbot.net-->
<script language='JavaScript1.2'>
function disableselect(e){
return false
}
function reEnable(){
return true
}
document.onselectstart=new Function (&quot;return false&quot;)
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script><span style="font-size: large;">
</span>
  • If you're using Blogger, you'll need to add the above code to your theme's template after the <head> tag.

Disable Copy Paste Using CSS + Enable Copy Paste For Some Content:


1
2
3
4
5
6
7
8
9
10
11
12
13
/*----- Disable Text Selection with CSS Code ------*/
.post blockquote {
-webkit-user-select: text !important;
-moz-user-select: text !important;
-ms-user-select: text !important;
user-select: text !important;
}
body {
-webkit-user-select: none !important;
-moz-user-select: -moz-none !important;
-ms-user-select: none !important;
user-select: none !important;
}

  • If you're using Blogger, you'll need to include the above CSS code before]]>/b:skin> in your theme's template.
  • If you're using Blogger, you'll need to put the above CSS code in your theme's template before]]>/b:skin>.

Disable Copy Paste For Whole Page Using CSS:


1
2
3
4
5
6
7

/*----- Disable Text Selection with CSS Code-------*/
body {
-webkit-user-select: none !important;
-moz-user-select: -moz-none !important;
-ms-user-select: none !important;
user-select: none !important;
}


Swift 3:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
open override func target(forAction action: Selector, withSender sender: Any?) -> Any? {
    guard isReadonly else {
        return super.target(forAction: action, withSender: sender)
    }
  
    if #available(iOS 10, *) {
        if action == #selector(UIResponderStandardEditActions.paste(_:)) {
            return nil
        }
    } else {
        if action == #selector(paste(_:)) {
            return nil
        }
    }
  
    return super.target(forAction: action, withSender: sender)
}


Post a Comment

Previous Post Next Post