docs.rodeo

MDN Web Docs mirror

Screen: lockOrientation() method

{{APIRef("Screen Orientation API")}} {{Deprecated_Header}} 

The lockOrientation() method of the {{DOMxRef("Screen")}}  interface locks the screen into a specified orientation.

[!WARNING] This feature is deprecated and should be avoided. Use the {{DOMxRef("ScreenOrientation.lock()")}}  method instead.

[!NOTE] This method only works for installed Web apps or for Web pages in fullscreen mode.

Syntax

lockOrientation(orientation)

Parameters

[!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 return value doesn’t indicate that the screen orientation is indeed locked: there may be a delay.

Examples

Usage with a string 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

This feature is not part of any specification. It is no longer on track to becoming a standard.

Use {{domxref("ScreenOrientation.lock()")}}  instead.

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN