有没有办法判断Safari是否为全屏显示?(例如document.fullscreenElement)

Sam*_*Fen 4 safari html5 fullscreen

我正在尝试使用Javascript查找Safari是否处于全屏模式。Chrome和Mozilla都使用供应商前缀的document.fullscreenElement版本:

isFullscreen = function() {
  return document.fullscreenElement
      || document.webkitFullscreenElement
      || document.mozFullScreenElement;
}
Run Code Online (Sandbox Code Playgroud)

但是,这在Safari 5.1.7上不起作用-文档上没有“ webkitFullscreenElement”或类似属性。

有人知道是否有办法判断Safari是否处于全屏模式吗?

小智 6

很难找到这个,但是您要寻找的属性是:

document.webkitCurrentFullScreenElement
Run Code Online (Sandbox Code Playgroud)

如您所见,它根本没有遵循标准,甚至没有遵循标准。

还值得一提,因为它与之相关:检查是否支持全屏模式的属性也很难找到(我仍然没有...),因此我要检查支持情况:

if (typeof document.webkitCurrentFullScreenElement !== 'undefined') ...
Run Code Online (Sandbox Code Playgroud)

因为该属性将为null(或全屏元素)。