有没有办法判断Safari是否全屏

有没有办法判断Safari是否全屏

本文介绍了有没有办法判断Safari是否全屏?(例如 document.fullscreenElement)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to find out whether Safari is in fullscreen mode using Javascript. Chrome and Mozilla both use vendor-prefixed versions of document.fullscreenElement:

isFullscreen = function() {
  return document.fullscreenElement
      || document.webkitFullscreenElement
      || document.mozFullScreenElement;
}

但是,这在 Safari 5.1.7 上不起作用——文档上没有webkitFullscreenElement"或类似的属性.

However, this doesn't work on Safari 5.1.7 -- there is no "webkitFullscreenElement" or similar property on document.

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

Does anyone know if there's a way to tell whether Safari is in fullscreen mode?

推荐答案

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

It's pretty hard to find this one, but the property you are looking for is:

document.webkitCurrentFullScreenElement

如您所见,它不符合标准,甚至根本不符合标准.

As you can see it doesn't follow standard, not even close, at all.

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

Also worth to mention as it is related: the property to check if fullscreen mode is supported is also hard to find (I still haven't...) so to check for support I do:

if (typeof document.webkitCurrentFullScreenElement !== 'undefined') ...

因为属性将为空(或全屏元素).

as the property will be null (or the fullscreen element).

这篇关于有没有办法判断Safari是否全屏?(例如 document.fullscreenElement)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 13:26