Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Screen.lockOrientation()

Cette traduction est incomplète. Aidez à traduire cet article depuis l'anglais.

Cette fonction est expérimentale
Puisque cette fonction est toujours en développement dans certains navigateurs, veuillez consulter le tableau de compatibilité pour les préfixes à utiliser selon les navigateurs.
Il convient de noter qu'une fonctionnalité expérimentale peut voir sa syntaxe ou son comportement modifié dans le futur en fonction des évolutions de la spécification.

La méthode lockOrientation vérouille l'affichage dans une orientation définie.

Note: Cette méthode fonction uniquement pour les application web installée et les pages web en plein écran.

Syntax

lockedAllowed = window.screen.lockOrientation(orientation);

Parameters

orientation
The orientation into which to lock the screen. This is either a string or an array of strings. Passing several strings lets the screen rotate only in the selected orientations.

The following strings represent the possible orientation requirements you may specify.

portrait-primary
It represents the orientation of the screen when it is in its primary portrait mode. A screen is considered in its primary portrait mode if the device is held in its normal position and that position is in portrait, or if the normal position of the device is in landscape and the device held turned by 90° clockwise. The normal position is device dependant.
portrait-secondary
It represents the orientation of the screen when it is in its secondary portrait mode. A screen is considered in its secondary portrait mode if the device is held 180° from its normal position and that position is in portrait, or if the normal position of the device is in landscape and the device held is turned by 90° anticlockwise. The normal position is device dependant.
landscape-primary
It represents the orientation of the screen when it is in its primary landscape mode. A screen is considered in its primary landscape mode if the device is held in its normal position and that position is in landscape, or if the normal position of the device is in portrait and the device held is turned by 90° clockwise. The normal position is device dependant.
landscape-secondary
It represents the orientation of the screen when it is in its secondary landscape mode. A screen is considered in its secondary landscape mode if the device held is 180° from its normal position and that position is in landscape, or if the normal position of the device is in portrait and the device held is turned by 90° anticlockwise. The normal position is device dependant.
portrait
It represents both portrait-primary and portrait-secondary.
landscape
It represents both landscape-primary and landscape-secondary.
default
It represents either portrait-primary and landscape-primary depends on natural orientation of devices. For example, if the panel resolution is 1280*800, default will make it landscape, if the resolution is 800*1280, default will make it to portrait.

Note: It's possible to set several locks at the same time. So, if the lock is set for only one orientation, the screen orientation will never change until the screen orientation is unlocked. Otherwise, the screen orientation will change from an orientation to another as long as the orientations are amongst the orientations the device has been locked to.

Return value

Returns true if the orientation was authorized to be locked or false if the orientation locking was denied. Note that the returns value doesn't indicate that the screen orientation is indeed locked: there may be a delay.

Examples

Usage with a DOMString argument

screen.lockOrientationUniversal = screen.lockOrientation || screen.mozLockOrientation || screen.msLockOrientation;

if (screen.lockOrientationUniversal("landscape-primary")) {
  // orientation was locked
} else {
  // orientation lock failed
}

Usage with an Array argument

screen.lockOrientationUniversal = screen.lockOrientation || screen.mozLockOrientation || screen.msLockOrientation;

if (screen.lockOrientationUniversal(["landscape-primary", "landscape-secondary"])) {
  // orientation was locked
} else {
  // orientation lock failed
}

Specifications

Specification Status Comment
Screen Orientation API
La définition de 'Screen Orientation' dans cette spécification.
Version de travail Initial definition

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 38[1] (Oui) moz[2] 11 ms[3] Pas de support Pas de support
Array argument Pas de support 18.0 (18.0) 11 ms Pas de support Pas de support
default Pas de support Pas de support Pas de support Pas de support Pas de support
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support Pas de support 38[1] (Oui) moz[2] Pas de support Pas de support Pas de support
Array argument Pas de support Pas de support 18.0 (18.0) Pas de support Pas de support Pas de support
default Pas de support Pas de support 26.0 (26.0) Pas de support Pas de support Pas de support

[1] A similar method is implemented using a newer standard syntax (screen.orientation.lock) and returns a Promise. While it exists on desktop, it will always fail.

[2] This API is only implemented as a prefixed method (screen.mozLockOrientation) in Firefox OS and Firefox for Android. Also, due to bug 966480, it does not work in Firefox for Android.

[3] This method is implemented using a prefix (screen.msLockOrientation) in Internet Explorer for Windows 8.1 and Windows RT 8.1. It is not supported on Windows 7.

See also

Étiquettes et contributeurs liés au document

 Contributeurs à cette page : Nik0w
 Dernière mise à jour par : Nik0w,