我正在为 JavaScript Fullscreen API 进行切换。不知何故,Webkit 浏览器中的退出全屏模式(else 语句)不起作用。有人可以暗示什么是错的吗?该代码是全屏 API 的 Mozilla 文档的示例代码。var toggleFullScreen;
toggleFullScreen = function() {
if ((document.fullScreenElement && document.fullScreenElement !== null) || (!document.mozFullScreenElement && !document.webkitFullScreenElement)) {
if (document.documentElement.requestFullScreen) {
return document.documentElement.requestFullScreen();
} else if (document.documentElement.mozRequestFullScreen) {
return document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullScreen) {
return document.documentElement.webkitRequestFullScreen();
} else {
return console.log("didnt happen");
}
} else {
if (document.cancelFullScreen) {
console.log("Mozilla Proposal cancels Fullscreen");
return document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
console.log("Firefox closes");
return document.mozCancelFullScreen();
// This is the line:
} else if (document.webkitCancelFullScreen) {
console.log("Webkit closes");
return document.webkitCancelFullScreen();
} else {
return console.log("Can't close");
}
}
};