关于页面全屏下iframe中video无法全屏问题
程序员文章站
2022-04-18 11:32:19
...
1.首先我们需要 iframe 允许全屏
<iframe frameborder="no" width="100%" height="100%"
allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" //这三个要加上,允许iframe内容全屏
src="http://localhost:9095/#/" ></iframe>
2.如果加上还不行,就需要把浏览器的F11全屏事件阻止掉,使用h5的全屏方法
<script>
window.onload = function(){
//屏蔽键盘事件
document.onkeydown = function (){
var e = window.event || arguments[0];
//F11
if(e.keyCode == 114){
handleFullScreen()
return false;
//Ctrl+Shift+I
}
};
//屏蔽鼠标右键
// document.oncontextmenu = function (){
// return false;
// }
}
// 全屏事件
function handleFullScreen(){
let element = document.documentElement;
if (this.fullscreen) {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
} else {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.msRequestFullscreen) {
// IE11
element.msRequestFullscreen();
}
}
}
</script>
上一篇: Vue单文件组件开发实现过程详解
下一篇: SpringMVC参数绑定,这篇就够了!