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 »



Related Examples



All JavaScript Examples

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.