Document.exitFullscreen()
方法用于让当前文档退出全屏模式(原文表述不准确,详见备注)。调用这个方法会让文档回退到上一个调用Element.requestFullscreen()
方法进入全屏模式之前的状态。
备注: 如果一个元素A在请求进去全屏模式之前,已经存在其他元素处于全屏状态,当这个元素A退出全屏模式之后,之前的元素仍然处于全屏状态。浏览器内部维护了一个全屏元素栈用于实现这个目的。
语法
document.exitFullscreen();
示例
// 点击切换全屏模式
document.onclick = function (event) {
if (document.fullscreenElement) {
document.exitFullscreen()
} else {
document.documentElement.requestFullscreen()
}
};
API规格
Specification | Status | Comment |
---|---|---|
Fullscreen API Document.exitFullscreen() |
Living Standard | Initial definition |
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes)-webkit 45 (unprefixed) |
9.0 (9.0) as mozCancelFullScreen [1]47.0 (47.0)[1] (behind full-screen-api.unprefix.enabled |
? | ? | ? |
Feature | Android Webkit | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes)-webkit 45 (unprefixed) |
(Yes)-webkit 45 (unprefixed) |
9.0 (9.0) as mozCancelFullScreen [1]47.0 (47.0)[1] (behind full-screen-api.unprefix.enabled |
? | ? | ? |
[1] 可通过Document.exitFullscreen()
方法让全屏元素栈的栈顶元素退出全屏状态,并让新的栈顶的元素进入全屏状态。此特征在Gecko 11.0 (Firefox 11.0 / Thunderbird 11.0 / SeaMonkey 2.8)中被实现.