Web*_*404 7 javascript browser fullscreen
我使用这个代码,我学会了使浏览器全屏(它工作),但我试图修改它的版本以退出全屏失败.处理这些非标准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.");
}
}
Run Code Online (Sandbox Code Playgroud)
电话:
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);
});
Run Code Online (Sandbox Code Playgroud)
exitFullScreen函数有什么问题?我该如何解决?
编辑:
"Oops. Request method false."exitFullScreen()使用参数调用该函数document.body的jsfiddle:
虽然全屏请求功能通常在浏览器中适用于我,但我无法在JSFiddle中使用它,我不确定这是因为我自己的错误,还是与JSFiddle有关.
为了进入全屏,大写有一些问题.
对于退出,你需要在它上面document而不是在它上面调用它body,你还需要正确地应用它而不是调用方法的引用.
所以requestMethod.call(element);也要退出.
请参阅http://jsfiddle.net/gaby/FGX72/show 上的演示
(在最新的IE/Chrome/FireFox上测试)