Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Right-Clicking In HTML5 Video?

I'm using an 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.

like image 831
user3517251 Avatar asked Apr 10 '14 15:04

user3517251


People also ask

How do I disable right click on videos?

ready(function() { $("video"). bind("contextmenu",function(){ return false; }); } ); This should disable right click on all the video elements in that page. Hope this helps.

How do I disable right click in HTML?

Disable right click menu in html page using jquery. JavaScript Code: $(document). bind("contextmenu",function(e){ return false; });

How do I disable right click on Vimeo?

Then use the following: $( sibling element ). on("contextmenu", function(e) { return false; });


2 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>
like image 58
jsherk Avatar answered Sep 24 '22 05:09

jsherk


 $(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.

like image 37
Atul Avatar answered Sep 21 '22 05:09

Atul