javascript 在 Safari 5.1.2 中传递 Element.ALLOW_KEYBOARD_INPUT 时 webkitRequestFullScreen 失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8427413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
webkitRequestFullScreen fails when passing Element.ALLOW_KEYBOARD_INPUT in Safari 5.1.2
提问by Geuis
Running into the following problem specifically in Safari 5.1.2 when attempting to use the javascript fullscreen api.
尝试使用 javascript 全屏 api 时,特别在 Safari 5.1.2 中遇到以下问题。
By copy and pasting the following lines into your browser on a loaded page, you can see the effect.
通过将以下几行复制并粘贴到已加载页面上的浏览器中,您可以看到效果。
This works in Chrome 15 and Safari 5.1.2:
这适用于 Chrome 15 和 Safari 5.1.2:
javascript:document.querySelector('body').webkitRequestFullScreen();
This works in Chrome 15 but fails silently in Safari 5.1.2:
这在 Chrome 15 中有效,但在 Safari 5.1.2 中静默失败:
javascript:document.querySelector('body').webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
ALLOW_KEYBOARD_INPUT seems like it should work in Safari, according to documentation here: http://developer.apple.com/library/safari/#documentation/WebKit/Reference/ElementClassRef/Element/Element.html
根据此处的文档,ALLOW_KEYBOARD_INPUT 似乎应该在 Safari 中工作:http: //developer.apple.com/library/safari/#documentation/WebKit/Reference/ElementClassRef/Element/Element.html
Any ideas why this isn't working?
任何想法为什么这不起作用?
回答by Tony
This is known Safari bug. It can be sniffed during full screen switching:
这是已知的 Safari 错误。可以在全屏切换时嗅探:
someElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
if (!document.webkitCurrentFullScreenElement) {
// Element.ALLOW_KEYBOARD_INPUT does not work, document is not in full screen mode
}
Use this real time sniffing and thus your code will support future fixing bug in Safari.
使用这种实时嗅探,因此您的代码将支持未来在 Safari 中修复错误。
回答by taochengzhou
someElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT)
works in chrome.
someElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT)
在 chrome 中工作。
And someElement.webkitRequestFullScreen()
works in safari 5.1.7
并someElement.webkitRequestFullScreen()
在 safari 5.1.7 中工作
All test base on windows 7.
所有测试均基于 Windows 7。
回答by user123444555621
I just ran into the same issue, and this is most definitely a bug.
我刚刚遇到了同样的问题,这绝对是一个错误。
This may be a case of the Undetectables. Guess we're gonna have to use good ol' browser sniffing.
这可能是Undetectables 的一个案例。猜猜我们将不得不使用良好的浏览器嗅探。
...(/Safari/.test(navigator.userAgent) ? undefined : Element.ALLOW_KEYBOARD_INPUT)
[edit] ...in which case keyboard input isn't possible. So I guess it's best to cut out fullscreen mode in Safari for the time being [/edit]
[编辑] ...在这种情况下键盘输入是不可能的。所以我想最好暂时在 Safari 中关闭全屏模式 [/edit]
Keep in mind that the fullscreen API is in a very early stage at the moment, and should not be used in production
请记住,全屏 API 目前处于非常早期的阶段,不应在生产中使用