ExitFullScreen无法正常工作+无论如何键盘按下按钮点击?

时间:2014-03-29 00:52:38

标签: javascript jquery html fullscreen

我的浏览器: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可以触发键盘按下退出键,它也可以全屏退出,或者这是不可能的?

1 个答案:

答案 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();
  }
}

DEMO