• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

JS: Detect User's Resolution, >1 Screens?

Joined
Aug 17, 2008
Messages
2,190 (0.38/day)
Location
Minnesota, USA
System Name TaichiTig
Processor i7 6800K
Motherboard ASRock X99 Taichi
Memory 32GB DDR4 3200
Video Card(s) RTX 4070
Storage SSD + Misc. HDDs in DrivePool
Display(s) BenQ PD3200U, Samsung C32HG70
Case Antec Twelve Hundred
Audio Device(s) Behringer UMC404HD, LSR308, Shure SRH840, AKG K612, Etymotic HF5
Power Supply Corsair 750TX
Mouse Logitech G502
Keyboard Deck Legend Ice Tactile
Software Win10
I'm using JavaScript's screen.width and screen.height to detect the screen resolution of a web page's users. This works fine regardless of the number of monitors a user has, except in IE and Opera.

IE seems to return the current screen resolution of whichever display is set in Windows as the primary display.

Opera seems to return the resolution of whichever display it was originally opened in, when it was opened—even if the resolution of that display has since been changed. Cheater.

I already have separate code in place to detect the height and width of the browser window/frame. Can anyone help me get the actual screen resolution of the screen the browser is currently in? Thanks. :)

FYI I have only tested in Chrome 12, Firefox 5, IE 8 and 9, Opera 11.5, and Safari 5.0.5 so far. The demographics of this web site's users also demand compatibility with Chrome 10 and 11, Firefox 3.6 and 4, IE 6 and 7, Opera 10.5 and 11.5, and Safari 3.2 and 4.
 

W1zzard

Administrator
Staff member
Joined
May 14, 2004
Messages
27,049 (3.71/day)
Processor Ryzen 7 5700X
Memory 48 GB
Video Card(s) RTX 4080
Storage 2x HDD RAID 1, 3x M.2 NVMe
Display(s) 30" 2560x1600 + 19" 1280x1024
Software Windows 10 64-bit
design your html in a way that it works without knowing the resolution

what are you trying to do anyway?
 
Joined
Aug 17, 2008
Messages
2,190 (0.38/day)
Location
Minnesota, USA
System Name TaichiTig
Processor i7 6800K
Motherboard ASRock X99 Taichi
Memory 32GB DDR4 3200
Video Card(s) RTX 4070
Storage SSD + Misc. HDDs in DrivePool
Display(s) BenQ PD3200U, Samsung C32HG70
Case Antec Twelve Hundred
Audio Device(s) Behringer UMC404HD, LSR308, Shure SRH840, AKG K612, Etymotic HF5
Power Supply Corsair 750TX
Mouse Logitech G502
Keyboard Deck Legend Ice Tactile
Software Win10
design your html in a way that it works without knowing the resolution

what are you trying to do anyway?

The question isn't about page design, it is "Can anyone help me get the actual screen resolution of the screen the browser is currently in?" Page design is already optimized for a wide array of resolutions and is enhanced aesthetically and functionally for users whose specific browser/frame res can be reliably detected as mentioned in the OP.

Respectfully, again I'm just looking for the answer to the question "Can anyone help me get the actual screen resolution of the screen the browser is currently in?"
 
Joined
Feb 8, 2005
Messages
1,675 (0.24/day)
Location
Minneapolis, Mn
System Name Livingston
Processor i7-4960HQ
Motherboard macbook prp retina
Cooling Alphacool NexXxoS Monsta (240mm x 120mm x 80mm)
Memory 16Gb
Video Card(s) Zotac Arctic Storm Nvidia 980ti
Display(s) 1x Acer XB270HU, 1x Catleap, 1x Oculus
Benchmark Scores http://www.3dmark.com/fs/770087
What W1zzard said is probably your best bet, your other option would be to use analytic software like piwik to find the monitor resolution, and cross reference if they are using dual monitors. I attached an image of the piwik interface to give you an idea of what I mean.

Although this is not a real time solution, it will only tell you the resolution (I believe) of the monitor the window was on at page load.​
Piwik-›-Web-Analytics-Reports.jpg

Hope thats of some use! http://piwik.org/
 
Joined
Aug 17, 2008
Messages
2,190 (0.38/day)
Location
Minnesota, USA
System Name TaichiTig
Processor i7 6800K
Motherboard ASRock X99 Taichi
Memory 32GB DDR4 3200
Video Card(s) RTX 4070
Storage SSD + Misc. HDDs in DrivePool
Display(s) BenQ PD3200U, Samsung C32HG70
Case Antec Twelve Hundred
Audio Device(s) Behringer UMC404HD, LSR308, Shure SRH840, AKG K612, Etymotic HF5
Power Supply Corsair 750TX
Mouse Logitech G502
Keyboard Deck Legend Ice Tactile
Software Win10
Thanks GSG-9, looking into it. :toast:
 
Top