javascript 如何在全屏模式下自动打开网页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19355370/
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
How to open a web page automatically in full screen mode
提问by shakthydoss
How do I open a web page automatically in full screen mode?
如何在全屏模式下自动打开网页?
I am looking for a solution to open an web page automatically in full screen mode, without expecting user to users press F11 or any other browser-specifc key.
我正在寻找一种在全屏模式下自动打开网页的解决方案,而不希望用户按 F11 或任何其他浏览器特定的键。
I've searched a lot, but I just could not find a solution.
我已经搜索了很多,但我只是找不到解决方案。
Is there a script or library or browser specific API available to help me achieve this?
是否有脚本、库或浏览器特定的 API 可以帮助我实现这一目标?
回答by BrownEyes
For Chrome via Chrome Fullscreen API
对于 Chrome,通过Chrome Fullscreen API
Note that for (Chrome) security reasons it cannot be called or executed automatically, there must be an interaction from the user first. (Such as button click, keydown/keypress etc.)
请注意,出于 (Chrome) 安全原因,它无法自动调用或执行,必须先有来自用户的交互。(如按钮点击、按键/按键等)
addEventListener("click", function() {
var
el = document.documentElement
, rfs =
el.requestFullScreen
|| el.webkitRequestFullScreen
|| el.mozRequestFullScreen
;
rfs.call(el);
});
Javascript Fullscreen API as demo'd by David Walshthat seems to be a cross browser solution
Javascript Fullscreen API as demo'd by David Walsh这似乎是一个跨浏览器的解决方案
// Find the right method, call on correct element
function launchFullScreen(element) {
if(element.requestFullScreen) {
element.requestFullScreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
}
}
// Launch fullscreen for browsers that support it!
launchFullScreen(document.documentElement); // the whole page
launchFullScreen(document.getElementById("videoElement")); // any individual element
回答by Jitendra Pancholi
Only works in IE:
仅适用于 IE:
window.open ("mapage.html","","fullscreen=yes");
window.open('','_parent','');
window.close();
回答by Helen Cui
It's better to try to simulate a webbrowser by yourself.You don't have to stick with Chrome or IE or else thing.
最好自己尝试模拟一个网页浏览器。你不必坚持使用Chrome或IE之类的东西。
If you're using Python,you can try package pyQt4 which helps you to simulate a webbrowser. By doing this,there will not be any security reasons and you can set the webbrowser to show in full screen mode automatically.
如果您使用 Python,您可以尝试包 pyQt4,它可以帮助您模拟网络浏览器。通过这样做,不会有任何安全原因,您可以将网络浏览器设置为自动以全屏模式显示。
回答by Udit mehra
<div class="container">
<section class="main-content">
<center><a href="#"><button id="view-fullscreen">view full size page large</button></a><center>
<script>(function () {
var viewFullScreen = document.getElementById("view-fullscreen");
if (viewFullScreen) {
viewFullScreen.addEventListener("click", function () {
var docElm = document.documentElement;
if (docElm.requestFullscreen) {
docElm.requestFullscreen();
}
else if (docElm.mozRequestFullScreen) {
docElm.mozRequestFullScreen();
}
else if (docElm.webkitRequestFullScreen) {
docElm.webkitRequestFullScreen();
}
}, false);
}
})();</script>
</section>
</div>
for view demo clcik here demo of click to open page in fullscreen
如需查看演示,请点击此处单击以全屏打开页面的演示
回答by Jart Jet
window.onload = function() {
var el = document.documentElement,
rfs = el.requestFullScreen
|| el.webkitRequestFullScreen
|| el.mozRequestFullScreen;
rfs.call(el);
};
回答by BigCoder
You can go fullscreen automatically by putting this code in:
您可以通过将此代码放入以下代码自动全屏显示:
var elem = document.documentElement; if (elem.requestFullscreen) { elem.requestFullscreen() }
demo: https://codepen.io/ConfidentCoding/pen/ewLyPX
演示:https: //codepen.io/ConfidentCoding/pen/ewLyPX
note: does not always work for security reasons. but it works for me at least. does not work when inspecting and pasting the code.
注意:出于安全原因,并不总是有效。但至少对我有用。检查和粘贴代码时不起作用。