【发布时间】:2014-08-03 23:53:01
【问题描述】:
Here's documentation on exiting fullscreen mode.
我使用了这段代码,我学会了让浏览器全屏显示(它有效),但我尝试修改它的版本以退出全屏失败。处理这些非标准 API 有点棘手,每个浏览器的实现方式都略有不同。
代码如下:
// Bring the page into full-screen mode - Works!
function requestFullScreen(element) {
// Supports most browsers and their versions.
var requestMethod = element.requestFullScreen ||
element.webkitRequestFullScreen ||
element.mozRequestFullScreen ||
element.msRequestFullScreen;
if (requestMethod) {
requestMethod.call(element);
} else if ( typeof window.ActiveXObject !== "undefined") {
var wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
}
}
// Exit fullscreen - Doesn't work!
function exitFullScreen(element){
var requestMethod = element.exitFullscreen ||
element.mozCancelFullScreen ||
element.webkitExitFullscreen ||
element.msExitFullscreen;
if (requestMethod) {
requestMethod();
} else {
console.log("Oops. Request method false.");
}
}
还有电话:
var $fullscreenButton = $("#fullscreen-button");
var $smallscreenButton = $("#smallscreen-button");
$fullscreenButton.on("click", function() {
var elem = document.body;
// Make the body go full screen.
requestFullScreen(elem);
});
$smallscreenButton.on("click", function() {
var elem = document.body;
// Exit full screen.
exitFullScreen(elem);
});
exitFullScreen 函数有什么问题?我该如何解决?
编辑:
- 我正在为此开发 JSFiddle!
- “不起作用”是指它输出
"Oops. Request method false." - 我正在使用参数
document.body调用函数exitFullScreen()
JSFiddle:
虽然全屏请求功能在我的浏览器中正常工作,I could not get it to work in JSFiddle,但我不确定这是因为我自己的错误,还是与 JSFiddle 有关。
【问题讨论】:
-
也许评论一下为什么投反对票?这些天几乎不可能在 Stackoverflow 上提出问题,这里的每个人都像疯了一样投反对票,没有提出改进建议,只是攻击任何不完美的问题,或笼统的问题,或者......无论你们在这里寻找什么这些日子。在其他 Stack Exchange 社区中,有如此多的问题得到了投票和良好的反馈。在这里,就好像整个系统都下地狱了。这么多人的负面反应.. 只是我的观察:)
-
@MatthewLock 不,你错了。工作示例适用于 Code Review.SE - Stack Overflow 适用于不起作用的代码。此代码易于验证,已简化为我的精确问题,并且完全直接。
-
您是否在控制台中遇到错误?您遇到什么浏览器问题?我相信@MatthewLock 的目标是sscce.org,但事实并非如此。这不是必需的(AFAIK),但它肯定有帮助;用户可以出于他们想要的任何原因投票,因此他们不会被捆绑在一起。我也不会因为投票而陷入泡沫,这只是浪费精力。
-
@WebDeveloper404, "不起作用" 不是很有帮助.. 什么不起作用?你有错误吗?你有你自己的ˋconsole.logˋ消息吗?你怎么称呼这些方法?你在传递什么论点?哪些浏览器出现问题?这些问题中的每一个都可能是失败的原因..
-
@GabyakaG.Petrioli 我已将这些详细信息添加到问题中。感谢您提出的改进建议!
标签: javascript browser fullscreen