JavaScript Element exitFullscreen() 方法
exitFullscreen()方法在全屏模式下取消元素。
注意:此方法需要特定的前缀才能在不同的浏览器中工作(请参阅下面的浏览器支持)。
提示:使用requestFullscreen()方法以全屏模式打开元素。
实例:
以全屏模式打开HTML页面,然后单击按钮将其关闭:
/* 获取documentElement(< html>)以全屏显示页面 */
var elem = document.documentElement;
/* 全屏查看 */
function openFullscreen() {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) { /* Firefox */
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) { /* IE/Edge */
elem.msRequestFullscreen();
}
}
/* 关闭全屏 */
function closeFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) { /* Firefox */
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) { /* IE/Edge */
document.msExitFullscreen();
}
}
尝试一下