我在具有视频背景的登录页面上有一个英雄,并希望阻止webm/mp4文件在移动设备上下载.我见过一些涉及带display:none属性的媒体查询的解决方案.虽然他们在第一印象时表现很好,但我使用连接到手机的Chrome调试工具验证了该文件仍在下载.
以下是HTML5标记中显示的视频:
<video preload="metadata" class="hidden-xs" autoplay="autoplay" poster="fallback-image.jpg" loop="loop" id="bgvid">
<source src="video.webm" type="video/webm">
<source src="video.mp4" type="video/mp4">
</video>
Run Code Online (Sandbox Code Playgroud)
以下是我用来检测移动浏览器的方法:
function detectmob() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
){
// If mobile, then we do all this
}
else {
// If not mobile then do this
}
} // detectmob
Run Code Online (Sandbox Code Playgroud)
如何防止有人在我的JavaScript功能中在移动设备上下载视频?