Is there a way to display a window's screen size as a number? I'd be super handy for testing responsiveness.
Get the size of the screen, current web page and browser window
How exact should I be with windows?
How to measure a window
How to measure existing window? I feel like this is a stupid question
What's the most common browser window dimensions? For avoiding fingerprinting.
Where do I measure to get the window size?
Window Measurements - Is this a 35-3/8 x 59-1/4 or 36 x 60?
How do I know what window size I need?
What size is a standard bedroom window size?
Are replacement windows sized the same as new construction windows?
Videos
You could use a simple tool like WinSpy or the Window Spy tool included in the AutoHotKey package.
You can make your own
Copy following two files to a folder.
To Use:
GetWindowRect <Title Of Window>
EG
GetWindowRect Untitled - Notepad
Change /target:exe to /target:winexe to make it a non console program
REM GetWindowRect.bat
REM This file compiles GetWindowRect.vb to GetWindowRect.exe
REM GetWindowRect.exe reports on Windows position
REM To use
REM GetWindowRect
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:exe /out:"%~dp0\GetWindowRect.exe" "%~dp0\GetWindowRect.vb"
pause
;GetWindowRect.vb
imports System.Runtime.InteropServices
Public Module GetWindowRect
<StructLayout(LayoutKind.Sequential)> _
Private Structure RECTL
Public Left As UInt32
Public Top As UInt32
Public Right As UInt32
Public Bottom As UInt32
End Structure
Private Declare Function GetWindowRect Lib "User32" (ByVal hWnd as IntPtr, ByRef Rect as RectL) as Integer
Public Declare UNICODE Function FindWindowW Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Sub Main
On Error Resume Next
Dim hWindows as IntPtr
Dim Ret as Integer
hwindows = FindWindowW(vbNullString, Command())
If hwindows = 0 then
Msgbox(Command() & " cannot be found.")
Else
Dim x as RectL
Ret = GetWindowRect(hWindows, x)
If Ret = 0 Then
MsgBox("GetWindowRect Error " & Err.LastDllError)
Else
'Delete the MsgBox line if using as console program
Msgbox(x.left & " " & x.top & " " & x.right & " " & x.bottom)
Console.Writeline(x.left & " " & x.top & " " & x.right & " " & x.bottom)
End If
End If
End Sub
End Module
Also available here - https://winsourcecode.blogspot.com/2020/01/getwindowrectexe-reports-on-windows.html
I want the number to change as I adjust the window's screen size, letting me know what screen size I'm at.
Edit: Awesome answers, guys!! Thanks so much!!!
These days, for screen size you can use the screen object:
window.screen.height;
window.screen.width;
Legacy
You can get the size of the window or document with jQuery:
// Size of browser viewport.
$(window).height();
$(window).width();
// Size of HTML document (same as pageHeight/pageWidth in screenshot).
$(document).height();
$(document).width();
This has everything you need to know: Get viewport/window size
but in short:
var win = window,
doc = document,
docElem = doc.documentElement,
body = doc.getElementsByTagName('body')[0],
x = win.innerWidth || docElem.clientWidth || body.clientWidth,
y = win.innerHeight|| docElem.clientHeight|| body.clientHeight;
alert(x + ' × ' + y);
Fiddle
Please stop editing this answer. It's been edited 22 times now by different people to match their code format preference. It's also been pointed out that this isn't required if you only want to target modern browsers - if so you only need the following:
const width = window.innerWidth || document.documentElement.clientWidth ||
document.body.clientWidth;
const height = window.innerHeight|| document.documentElement.clientHeight||
document.body.clientHeight;
console.log(width, height);