nodejs 视频使用blob隐藏真实地址,h5视频防下载
2020-06-10 本文已影响0人
多啦梦_1adc
废话少说,直接上效果,看代码

<body>
<video id="sound" width="200" controls="controls"></video>
</body>
<script type="text/javascript">
$(document).ready(function(){
$('#sound').bind('contextmenu',function() { return false; });//禁止js右键,防下载
//创建XMLHttpRequest对象
var xhr = new XMLHttpRequest();
//配置请求方式、请求地址以及是否同步
xhr.open('GET', 'http://localhost:3000/', true);
//设置请求结果类型为blob
xhr.responseType = 'blob';
//请求成功回调函数
xhr.onload = function(e) {
if (this.status == 200) {//请求成功
//获取blob对象
var blob = this.response;
//隐藏真实地址
$("#sound").attr("src", URL.createObjectURL(blob));
}
};
xhr.send();
})