Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Get Browser Viewport Dimensions</title> </head> <body> <script> function windowSize(){ var w = window.innerWidth; var h = window.innerHeight; alert("Width: " + w + ", " + "Height: " + h); } </script> <button type="button" onclick="windowSize();">Get Window Size</button> </body> </html>