JavaScript or JQuery

How to disable right-click | copy, paste in jquery, CSS, JavaScript?

There are several ways to disable the mouse right click. It prevents the copy and pasting in JavaScript.

Use oncontextmenu to prevent copy text from web pages.

One way to disable the mouse right-click is to use the “oncontextmenu” event. This event occurs when the user right-clicks on an element. You can use the oncontextmenu event to display a custom menu or to cancel the default menu.

    oncontextmenu="return false"  
    onselectstart="return false" 
    ondragstart="return false" > 

    <!-- html code here --> 

See the live demo here.

Disable the mouse right-click by using CSS.

You can use the “user-select” property to prevent the mouse right click.

When you double-click on text in a web browser, it is selected or highlighted. This can be avoided by using this property.

The “user-select” property is supported in Internet Explorer, Firefox, and Safari.

p {

The interactive demo is available here

Use jQuery to prevent content copying and pasting from your website

We’ll demonstrate how to use jQuery to avoid content theft from your website. You may quickly disable the mouse right-click as well as cut, copy, and paste from web content by using jQuery.

Examples of jQuery

 //Disable full page
        return false;

If you want to apply this feature to a specific element then you can use ID.

//Disable part of page
        return false;

You can also show messages on the screen

$(document).bind("contextmenu", function (e) {
  alert("Right Click is Disabled");

Disable Cut Copy and Paste

The following JavaScript code will prevent users from cut, copy, and pasting entire or specific elements of your website.

    //Disable for entire page
    $('body').bind('cut copy paste', function (e) {
    //Disable specific element on page
    $('#id').bind('cut copy paste', function (e) {

Disable ctrl+v, ctrl+x and ctrl+c.

// disable ctrl+x
$('textarea').on("cut", function(e) {
    $("#d2").text('cut. not allowed!');

// disable ctrl+c
$('textarea').on("copy", function(e) {
    $("#d2").text('copy. not allowed!');

// disable ctrl+v
$('textarea').on("paste", function(e) {
    $("#d2").text('paste. not allowed!');

Add comment