BootstrapCSSHTMLJavascript

Disable Right Click on Website

By February 16, 2018 No Comments

This is an example of how to disable right clicking on a website using JavaScript and Bootstrap.

You could leave Bootstrap off completely and use the basic alert functionality, but it’s not as clean looking to the end user and limits some of the customization.

The following is the JavaScript code used to listen and catch the right click action anywhere on your page.  When a user right clicks it shows the Bootstrap Modal and stops the right click function from firing.

<script>
    $(document).on('contextmenu', function() {
        $('#exampleModal').modal('show');
        return false;
    });
</script>

Below is the script inserted on an example page.  You can view the demo of it in action here.

Keep in mind just because you disable the right click functionality on your website doesn’t mean your content is safe.  There are many other methods someone with the right knowledge could use to download media assets or copy text from your website.  If you don’t want your assets copied or downloaded then don’t put it on the internet to begin with.

View the Prodjex Web Development forum discussion on How to disable right click on a website using JavaScript and a Bootstrap Modal.

Leave a Reply