javascript 在 Chrome 中强制全屏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8126996/
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
Force full screen in Chrome
提问by BenM
I am currently working on a private web application that is not going to be released to the public. It is relatively straightforward and will run on Google Chrome.
我目前正在开发一个不会向公众发布的私有 Web 应用程序。它相对简单,可以在 Google Chrome 上运行。
Does anyone have a solution for forcing the browser to enter Full Screen Mode
when the DOM is ready? I was thinking to simply simulate the keypress
of the F11 key, but I don't know if this is possible.
有没有人有Full Screen Mode
在 DOM 准备好时强制浏览器进入的解决方案?我想简单地模拟keypress
F11 键的 ,但我不知道这是否可能。
Does anyone have a jQuery solution, other than resizing the window to the available width and hiding the navigation (not an ideal solution).
除了将窗口大小调整为可用宽度并隐藏导航(不是理想的解决方案)之外,有没有人有 jQuery 解决方案。
回答by PeeHaa
As stated by others this isn't possible for obvious reasons already mentioned.
正如其他人所说,由于已经提到的明显原因,这是不可能的。
Although since it is a local site why don't you just create a Chrome shortcut for it in fullscreen:
虽然因为它是一个本地站点,为什么不在全屏模式下为它创建一个 Chrome 快捷方式:
Create a shortcut to Chrome:
创建 Chrome 的快捷方式:
"C:\Users\techiecorner\AppData\Local\Google\Chrome\Application\chrome.exe" --kiosk http://www.example.com
http://www.techiecorner.com/1941/how-to-auto-start-chrome-in-full-screen-mode-f11-everytime/
http://www.techiecorner.com/1941/how-to-auto-start-chrome-in-full-screen-mode-f11-everytime/
UDPATE
UDPATE
By now (HTML5) there is a proposal for a full screen API. To use this you could do something like:
现在 (HTML5) 有一个关于全屏 API 的提议。要使用它,您可以执行以下操作:
// feature detection
if (typeof document.cancelFullScreen != 'undefined' && document.fullScreenEnabled === true) {
// 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();
}
For more information see the official specs.
有关更多信息,请参阅官方规范。
回答by Pepijn
This is most likely not possible, I would consider this a security threat if it was.
这很可能是不可能的,如果是,我会认为这是一个安全威胁。
If you have control over the environment, you could accomplish this with AppleScript on Mac. Not sure about Windows.
如果您可以控制环境,则可以在 Mac 上使用 AppleScript 完成此操作。不确定 Windows。
回答by Roman
I doubt it is possible (not considering browser extensions).
我怀疑这是可能的(不考虑浏览器扩展)。
Browsers generally don't allow such kind of access to their window. Actually, modern browsers don't even allow you to change the size of the current window (only if it's a popup).
浏览器通常不允许对其窗口进行此类访问。实际上,现代浏览器甚至不允许您更改当前窗口的大小(仅当它是弹出窗口时)。
If it's crucial to your application, you should display a message to the user informing him to press F11 when the browser is not in fullscreen mode.
如果它对您的应用程序至关重要,您应该向用户显示一条消息,通知他在浏览器未处于全屏模式时按 F11 。
回答by Ray K
This is a no-can-do since you are trying to manipulate the actual program running on the OS. You can manipulate anything within the browser window, but not outside.
这是不可能的,因为您正试图操纵操作系统上运行的实际程序。您可以在浏览器窗口内操作任何东西,但不能在外面操作。
回答by Frank
This is a little late, but this gives you some experimental access to full screen aps. You can simulate a click event and get it to fire.
这有点晚了,但这使您可以对全屏应用程序进行一些实验性访问。您可以模拟点击事件并触发它。
https://github.com/martinaglv/jQuery-FullScreen
https://github.com/martinaglv/jQuery-FullScreen
A jQuery 1.7 plugin that wraps around the Full Screen API and works around various browser differences. Works in FF 10, Chrome and Safari. It is useful for presenting users with an easier to read version of your web pages, or zooming and elements.
一个 jQuery 1.7 插件,环绕全屏 API 并解决各种浏览器差异。适用于 FF 10、Chrome 和 Safari。它对于向用户展示更易于阅读的网页版本或缩放和元素很有用。