使用 Javascript 以编程方式将 Google Chrome 置于全屏模式?

发布于 2024-12-13 22:08:35 字数 334 浏览 1 评论 0原文

我最近在使用 YouTube 时,点击了 YouTube 视频中的全屏按钮,屏幕顶部出现一条消息,说我已进入全屏模式。此消息是您在键盘上按 f-11 时收到的本机消息。我还在某处读过一些东西(我现在找不到)说现在可以用 Javascript 来做到这一点。

问题

我如何根据命令将用户浏览器(Google Chrome)置于全屏? - 如果没有扩展,他们需要事先下载或任何类似性质的东西。

我正在使用 jQuery,所以这是最好的,但我根本找不到如何做到这一点。

编辑:我已经看到了这种性质的其他问题,但他们很久以前就被问到了,我相信这个功能是相当新的。

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.

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

裸钻 2024-12-20 22:08:35

这是一篇好文章:本机全屏 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();

Here is good article: Native Fullscreen JavaScript API . It describes all three methods: webkit, firefox and 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();
凶凌 2024-12-20 22:08:35

尝试这些功能,它们似乎是本机的:

void webkitRequestFullScreen();
void webkitRequestFullScreenWithKeys();
void webkitCancelFullScreen(); // only on Document

Try these functions, they appear to be native:

void webkitRequestFullScreen();
void webkitRequestFullScreenWithKeys();
void webkitCancelFullScreen(); // only on Document
冷︶言冷语的世界 2024-12-20 22:08:35

API 仍然在不断变化,尤其是自 W3C 本周加入以来。我花了一些时间研究这些差异,以便在 MediaElement.js HTML5 视频播放器中实现全屏,并且它在 Safari 5.1+、Chrome 15+ 或 Firefox Nightly 中运行良好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文