How To Include Full Screen Mode In The Web Application

Full screen mode is useful for video games, editing, and other purpose. So most of these types of applications use Fullscreen API  so the user can switch between full screen mode and the standard default mode.

Also we can program specifically to instruct the browser to switch to full screen.

To apply full screen mode we will use requestFullscreen() method

To set fullscreen document.documentElement.requestFullscreen()

To exit firescreen document.exitFullscreen()

The example Code


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        #change-display-mode {
            padding: 10px 20px;
            border: 2px solid #333;
            background-color: transparent;
            color: #333;
            font-size: 16px;
            text-transform: uppercase;
            cursor: pointer;
            transition: all 0.3s ease;
            outline: none;
        }

        #change-display-mode:hover {
            background-color: #333;
            color: #fff;
        }


    </style>
</head>

<body>
    <div>
        <button id="change-display-mode">To Fullscreen Mode</button>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            var fullscreenButton = document.getElementById('change-display-mode');

            function toggleFullscreen() {
                if (!document.fullscreenElement) {
                    document.documentElement.requestFullscreen();
                    fullscreenButton.textContent = "Exit Fullscreen";
                } else {
                    if (document.exitFullscreen) {
                        document.exitFullscreen();
                        fullscreenButton.textContent = "Go to  Fullscreen Mode";
                    }
                }
            }

            fullscreenButton.addEventListener('click', function () {
                toggleFullscreen();
            });
        });
    </script>
</body>

</html>
    

You can test this here

Related Posts

How to HTML open link in new in tab in browser
July 3, 2024

We can add this target=”_blank” in the <a> tag to open link in new tab Example code <!DOCTYPE html> <head> </head> <body> &lt!– Opens in the same tab –> <a href=”https://en.wikipedia.org/wiki/Main_Page”>Visit Wikipedia (same tab)</a> <br> &lt!– Opens in a new tab –> <a href=”https://en.wikipedia.org/wiki/Main_Page” target=”_blank”>Visit Wikipedia (new tab)</a> </body> </html> Copy Code

Change button text with jQuery
July 3, 2024

Its essential to change t he button text in some applications . For example Like button. If the current is “Like”, after click on the button it the button text will be “Liked” jquery makes process efficient. <!DOCTYPE html> <html> <head> <script src=”https://code.jquery.com/jquery-3.7.1.min.js”></script> </head> <body> <button class=”like-button”>Like</button> <script> $(document).ready(function(){ $(‘.like-button’).click(function(){ var buttonText = $(this).text(); if […]

How to get current time from browser in JavaScript
June 16, 2024

Current Time From Browser The current time is: We can get the current time with built- in JavaScript object Date To get the time we have to create the Date object first simply like this As we created the date object we can console.log to get the result We get the result like this. we […]