Syntax
js
requestFullscreen()
requestFullscreen(options)
Parameters
optionsOptional-
An object that controls the behavior of the transition to fullscreen mode. The available options are:
keyboardLockOptional-
Controls the selected keyboard lock mode.
"none"-
No keyboard lock is applied. This is the default mode.
"browser"-
Browser keyboard lock mode is applied. In this mode, the browser forwards keyboard events to the application that would normally be handled by browser or system code. Applications should intercept events for the keys and key combinations they want to use, and call
preventDefault()to cancel any default actions.Note that some browsers may disable the default action for some keys, such as the key that is normally used to exit fullscreen mode; this is not guaranteed, so you should always call
preventDefault(). Browsers are also encouraged to provide a mechanism to exit fullscreen mode with keyboard lock.For more information see the Keyboard locking section below.
navigationUIOptional-
Controls whether or not to show navigation UI while the element is in fullscreen mode. The default value is
"auto", which indicates that the browser should decide what to do."hide"-
The browser's navigation interface will be hidden and the entire dimensions of the screen will be allocated to the display of the element.
"show"-
The browser will present page navigation controls and possibly other user interface; the dimensions of the element (and the perceived size of the screen) will be clamped to leave room for this user interface.
"auto"-
The browser will choose which of the above settings to apply. This is the default value.
screenOptional-
Specifies on which screen you want to put the element in fullscreen mode. This takes a
ScreenDetailedobject as a value, representing the chosen screen.
Return value
A Promise which is resolved with a value of undefined when the transition to full screen is complete, or rejects with an exception.
Exceptions
On error the returned Promise rejects with one of the following values:
TypeError-
The
TypeErrorexception may be delivered in any of the following situations:- The document containing the element isn't fully active; that is, it's not the current active document.
- The element is not contained by a document.
- The element is not permitted to use the
fullscreenfeature, either because of Permissions Policy configuration or other access control features. - The element and its document are the same node.
- The element is a popover that is already being shown via
HTMLElement.showPopover().
NotSupportedErrorDOMException-
The passed
options.keyboardLockparameter is not supported by the browser.
Description
The requestFullscreen() method issues an asynchronous request to display the element in fullscreen mode.
The method requires permission.
- If permission to enter full screen mode is granted, the returned
Promisewill resolve and the element will receive afullscreenchangeevent to let it know that it's now in full screen mode. - If permission is denied, the promise is rejected and the element receives a
fullscreenerrorevent instead.
If the element has been detached from the original document, then the document receives these events instead.
Compatible elements
An element that you wish to place into fullscreen mode has to meet a small number of simple requirements: