简体   繁体   中英

how to disable download video option

i want to disable download video link from control panel of video tag.


     <video oncontextmenu="return false;" id="myVideo" autoplay controls>
        <source src="uploads/videos/<?php echo $vid;?>" type="video/mp4">
    </video>

That's very easy it seems that your using the HTML 5 Video and using your sample above, below is the code:

<video oncontextmenu="return false;" id="myVideo" autoplay controls controlsList="nodownload">
    <source src="uploads/videos/<?php echo $vid;?>" type="video/mp4">
</video>

Just add controlsList="nodownload" in your video tag.

Add below style to disable download link in video tag.

For Example:

<!DOCTYPE html>
<html>
<head>
<style>
   video::-internal-media-controls-download-button {
    display:none;
   }

   video::-webkit-media-controls-enclosure {
        overflow:hidden;
   }

   video::-webkit-media-controls-panel {
        width: calc(100% + 30px); 
   }
</style>
</head>

<body>

<video width="320" height="240" controls>
  <source src="add your video url" type="video/mp4">
</video>
</body>
</html>

For anyone that may be looking at this question from the future (Jetsons type beat) yes, controlList='nodownload' absolutely work. But I would suggest, instead of adding controlList in the video tag, do it in your js file. Because if someone starts playing around with your code, they could easily delete the controlsList property and still download it (if they are on a computer of course) So, to be safe - put it in your js file. Then obfuscate the js file. So, just in case you don't know what I mean - it should look like this (btw, I used jquery):

$(document).ready(() => {

$('video').attr('controlsList', 'nodownload');

});

And this will absolutely work and prevent people from just going in and deleting your video properties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM