Disable Right-Clicking In HTML5 Video?

I'm using a HTML5 video player on my website and I want to disable right clicking on all my videos.

I tried using this code and it doesn't work:

<script type="text/javascript">
$(document).ready(function(){
$('#videoElementID').bind('contextmenu',function() { return false; });
});
</script>

I'm using Wordpress and placed the function above in the header.php file.

How can I check what is the #videoElementID name for my player? I tried with all the DIV elements on the page and it still doesn't work.

I know this won't prevent users to download my videos but I really need to make this work.

Any ideas?

Thanks.

Answers


My favorite method which is quick and easy and does not require javascript is to add the oncontextmenu="return false;" to the video tag.

So something like this:

<video oncontextmenu="return false;" id="my-video-player" width="854" height="480" controls autoplay>
  <source src="https://example.com/link-to-my-video.mp4" type="video/mp4">
</video>

 $(document).ready(function() {
    $("video").bind("contextmenu",function(){
        return false;
        });
 } );

This should disable right click on all the video elements in that page. Hope this helps.


The right click menu is a function of the web browser. To disable it, you can try to add the following JavaScript to the head section of your web page, just before the tag.

jQuery(document).ready(function(){
    jQuery('video').bind('contextmenu',function() { return false; });
});

It works fine for me.

$(document).bind("contextmenu",function(ev){
    if(ev.target.nodeName=='VIDEO')
    {
        return false;
    }
});

Need Your Help

How do I generate insert statements with Sql server 2012?

sql-server sql-server-2012

I have sql server 2012 express and just installed the latest version of ssms tools from http://www.ssmstoolspack.com/Download

How can I avoid google mail server asking me to log in via browser?

email gmail captcha google-apps

I am trying to send emails from Django using an email configured by Google Apps, my configuration at the settings.py file looks something like this: