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); });
编辑:
>我正在为这个JSFiddle工作!
>通过“不工作”,我的意思是它输出“糟糕.请求方法错误”.
>我正在使用参数document.body调用函数exitFullScreen()
的jsfiddle:
虽然全屏请求功能通常在浏览器中适用于我,I could not get it to work in JSFiddle,我不确定这是因为我自己的错误,还是与JSFiddle有关.