×

Index

JavaScript Tutorial

JavaScript Examples

CSS Tutorial

CSS Examples

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>

JavaScript and HTML Code to Detect and Display Screen Resolution

<!--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



Comments and Discussions!

Load comments ↻





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