How to Disable Right Click in embed Tag using JavaScript

You can easily disable mouse right click in the web page, but it will not work in the <embed> and IFrame. If you want to disable right click in embed tag, JavaScript onmousedown event help to do that easily.

The main purpose of disabling right click is to prevent the user from saving the PDF or document content. In this tutorial shows how to disable right click in a pdf file opened in the iframe or <embed> tag.

The following example code will disable right-click on embedded PDF using JavaScript.

<script type="text/javascript">
document.onmousedown = disableRightclick;
var message = "Right click not allowed !!";
function disableRightclick(evt){
    if(evt.button == 2){
        alert(message);
        return false;    
    }
}
</script>

4 Comments

  1. Moses Said...
  2. Johnstone Said...
  3. Ravi Said...
    • CodexWorld Said...

Leave a reply

keyboard_double_arrow_up