Show a <video> element in fullscreen mode:
/* Get the element you want displayed in fullscreen */
var elem = document.getElementById("myvideo");
/* Function to open fullscreen mode */
function openFullscreen() {
/* If fullscreen mode is available, show the element in fullscreen */
if (document.fullscreenEnabled) {
/* Show the element in fullscreen */
elem.requestFullscreen();
}
}
Try it Yourself »
The fullscreenEnabled() method returns a Boolean value indicating whether the document can be viewed in fullscreen mode.
The fullscreenEnabled() method returns true if fullscreen mode is available, otherwise false.
Tip: Use the element.requestFullscreen() method to view an element in fullscreen mode.
Tip: Use the element.exitFullscreen() method to cancel fullscreen mode.
The numbers in the table specify the first browser version that fully supports the method. Note: Some browsers require a specific prefix (see parentheses):
Method | |||||
---|---|---|---|---|---|
fullscreenEnabled() | 71.0 45.0 (webkit) |
12.0 11.0 (ms) |
64.0 47.0 (moz) |
6.0 (webkit) | 58.0 15.0 (webkit) |
Using prefixes for cross-browser code:
/* If fullscreen mode is available, then do something */
if (
document.fullscreenEnabled || /* Standard syntax */
document.webkitFullscreenEnabled || /* Safari */
document.msFullscreenEnabled/* IE11 */
) {
...
}
Try it Yourself »
document.fullscreenEnabled()
None |
Return Value: | A Boolean value, indicating whether the document can be viewed in fullscreen mode:
|
---|
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!