使用 Javascript 以编程方式将 Google Chrome 置于全屏模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8016021/
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
Programmatically put Google Chrome into full-screen mode with Javascript?
提问by android.nick
I was on youtube recently when I clicked the fullscreen button by the youtube video and a message appeared at the top of the screen saying that I was put into full-screen mode. This message was the native message you get when pressing f-11 on your keyboard. I also read something somewhere(that I now cannot find) saying that it's now possible to do this with Javascript.
我最近在 youtube 上,当我点击 youtube 视频旁的全屏按钮时,屏幕顶部出现一条消息,说我已进入全屏模式。此消息是您在键盘上按 f-11 时收到的本机消息。我也在某处读到一些东西(我现在找不到)说现在可以用 Javascript 来做到这一点。
Question
问题
How would I put the users browser(Google Chrome) into fullscreen, on command? - without an extension they would need to download prior, or anything of that nature.
我如何根据命令将用户浏览器(谷歌浏览器)置于全屏模式?- 如果没有扩展,他们需要事先下载,或者任何类似的东西。
I'm using jQuery so that would be best, but I can't find how to do it at all.
我正在使用 jQuery,所以这是最好的,但我根本找不到如何去做。
EDIT: I've seen other questions of this nature, but they were asked a long time ago, and I believe this functionality is fairly new.
编辑:我已经看到了这种性质的其他问题,但他们很久以前就被问到了,我相信这个功能是相当新的。
回答by Lycha
Here is good article: Native Fullscreen JavaScript API. It describes all three methods: webkit, firefox and W3-proposal.
这是一篇好文章:本机全屏 JavaScript API。它描述了所有三种方法:webkit、firefox 和 W3-proposal。
// mozilla proposal
element.requestFullScreen();
document.cancelFullScreen();
// Webkit (works in Safari and Chrome Canary)
element.webkitRequestFullScreen();
document.webkitCancelFullScreen();
// Firefox (works in nightly)
element.mozRequestFullScreen();
document.mozCancelFullScreen();
// W3C Proposal
element.requestFullscreen();
document.exitFullscreen();
回答by Marc DiMillo
Try these functions, they appear to be native:
试试这些功能,它们似乎是原生的:
void webkitRequestFullScreen();
void webkitRequestFullScreenWithKeys();
void webkitCancelFullScreen(); // only on Document
回答by Rack-Mount Monitor
The API is still heavily in flux especially since the W3C joined in this week. I spent some time working through the differences to implement Full Screen in MediaElement.js HTML5 video player, and its working great in Safari 5.1+, Chrome 15+, or Firefox Nightly.
API 仍在不断变化,尤其是自 W3C 本周加入以来。我花了一些时间研究在 MediaElement.js HTML5 视频播放器中实现全屏的差异,它在 Safari 5.1+、Chrome 15+ 或 Firefox Nightly 中运行良好。