Fullscreen & Screen Orientation APIs
Fullscreen & Screen Orientation APIs in Modern JavaScript
For multimedia players, presentation tools, dashboards, and mobile web games, engaging the user requires removing browser chrome (toolbars, address bars) and managing display layout. The Fullscreen API and Screen Orientation API provide programmatic control over the viewport display mode.
1. The Fullscreen API
The Fullscreen API allows any HTML element—or the entire document—to expand to fill the entire physical screen.
Entering & Exiting Fullscreen:
2. Fullscreen Event & Pseudo-Class
Listening to Changes:
Styling with CSS :fullscreen Pseudo-Class:
3. The Screen Orientation API
Mobile web applications often require locking the display to landscape (for video/gaming) or portrait:
4. Security Requirement: User Gesture Gating
To prevent malicious websites from hijacking user screens, requestFullscreen() strictly requires a transient user gesture (e.g. click or key down). Calling element.requestFullscreen() automatically inside setTimeout() or on page load throws a TypeError: Permissions check failed.
Practice Quiz
Web Audio & MediaStream APIs Basics
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Geolocation, Clipboard & Device APIs | Web Audio & MediaStream APIs Basics |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.