我的浏览器:Google Chrome版本33.0.1750.154 m
脚本:
function exitFullscreen() {
var element = document.documentElement;
if (element.mozCancelFullScreen) {
element.mozCancelFullScreen();
} else if (element.webkitExitFullScreen) {
element.webkitExitFullScreen();
} else if (elem.exitFullScreen) {
element.exitFullScreen();
} else if (elem.msExitFullScreen) {
element.msExitFullScreen();
}
}
HTML:
<div class="menubutton" style="width: 100px;" onclick="exitFullscreen();">
<span class="menubuttontext">EXIT FULLSCREEN</span>
</div>
但是当我在fullscren模式下按下那个div时没有任何反应,我做错了,编写完全错误的代码还是不可能?
替代性的灵魂?如果点击按钮onclick可以触发键盘按下退出键,它也可以全屏退出,或者这是不可能的?
答案 0 :(得分:6)
有一个拼写错误(虽然它不会解决问题)
} else if (elem.exitFullScreen) { // should be element
element.exitFullScreen();
} else if (elem.msExitFullScreen) {
element.msExitFullScreen();
}
但exitFullscreen
应仅在document
对象上调用
function exitFullscreen() {
if(document.exitFullscreen) {
document.exitFullscreen();
} else if(document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if(document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}