ADVERTISEMENT
ADVERTISEMENT

JavaScript - Detect and Display Screen Resolution using JavaScript Function

In this example, we will learn how to detect and display Screen Resolution using JavaScript Function, we will create a JavaScript function that will detect and display using alert message box Screen Resolution on Button Click Event.

Detect and Display Screen Resolution using JavaScript Function

JavaScript function:

<script type="text/javascript">
    function displayResolution() {
        if (window.screen) {
            var width = screen.width;
            var height = screen.height;
            alert("Screen Resolution: " + width + "x" + height);
        }
    }
</script>

HTML Source Code with JavaScript:

<!--JavaScript - Detect and Display Screen Resolution using JavaScript Function.-->
<html>
    <head>
        <title>JavaScript - Detect and Display Screen Resolution using JavaScript Function.</title>
        <script type="text/javascript">
            function displayResolution() {
                if (window.screen) {
                    var width = screen.width;
                    var height = screen.height;
                    alert("Screen Resolution: " + width + "x" + height);
                }
            }
        </script>
    </head>

    <body style="text-align: center;">
        <h1>JavaScript - Detect and Display Screen Resolution using JavaScript Function.</h1>
        <p><input type="button" value="Display Screen Resolution." onclick="displayResolution()" /></p>
    </body>
</html>

Result

detect screen resolution using javascript function

JavaScript Examples »


ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.