<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#myP {
background-color: yellow;
padding: 20px;
font-size: 30px;
}
</style>
</head>
<body>
<h2>Fullscreen with JavaScript</h2>
<p>Click on the button to open this page in fullscreen mode.</p>
<button onclick="openFullscreen();">Go Fullscreen Mode</button>
<button onclick="closeFullscreen();">Close Fullscreen</button>
<p><strong>Tip:</strong> Press the "Esc" key to exit full screen.</p>
<p id="myP">I will display the event that was fired!</p>
<script>
var elem = document.documentElement;
function openFullscreen() {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) {
elem = window.top.document.body;
elem.msRequestFullscreen();
}
}
function closeFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();