Disable Right-Clicking In HTML5 Video?

前端 未结 5 1873
一个人的身影
一个人的身影 2020-12-16 02:41

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:

&l         


        
相关标签:
5条回答
  • 2020-12-16 03:08

    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; });
    });
    
    0 讨论(0)
  • 2020-12-16 03:08

    It works fine for me.

    $(document).bind("contextmenu",function(ev){
        if(ev.target.nodeName=='VIDEO')
        {
            return false;
        }
    });
    
    0 讨论(0)
  • 2020-12-16 03:12

    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>
    
    0 讨论(0)
  • 2020-12-16 03:18

    Better to use onContextMenu={(e) => e.preventDefault()} under the video tag of HTML5.

    0 讨论(0)
  • 2020-12-16 03:29
     $(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.

    0 讨论(0)
提交回复
热议问题