有些安卓浏览器下,HTML5 video会默认开启全屏播放,但有时我们需要禁止或限制用户的全屏操作,该怎么做?
在HTML5 video标签中,有一个fullscreen属性,可以用来控制全屏播放。在安卓浏览器中,该属性默认为true,也就是说视频会自动进入全屏模式。若要禁止全屏,可以通过以下两种方式实现:
var video = document.getElementsByTagName('video')[0]; video.removeAttribute('controls'); video.setAttribute('controls', 'true'); // 将fullscreen属性设置为true video.removeAttribute('controls'); video.setAttribute('controls', 'true'); // 再次设置控件以刷新全屏播放按钮
video::-webkit-media-controls-fullscreen-button { display: none; }
通过上述方式,就可以在安卓浏览器下禁止全屏播放。同时,控件仍然能够显示,用户可以通过控件来控制视频播放。