two phones - Android OS, HD, FHD screens. Height 720 + 1080 respectively. Now the problem is:

alert(window.screen.availHeight); alert(window.screen.height); alert(screen.height); //640 //640 //640 

Browsers - stock, chrome. I need phones with a screen resolution of less than 720 pixels in height to NOT execute the js script. What to do?
UPD: in the mobile emulator in chrome, the numbers are honest

  • tried using window.innerWidth / window.innerHeight or document.documentElement.clientWidth / document.documentElement.clientHeight? these things are tied to the size of the browser window - Dimon

1 answer 1

You forgot about such a thing as pixel ratio ( window.devicePixelRatio ), try this:

 var ratio = window.devicePixelRatio || 1; var w = screen.width * ratio; var h = screen.height * ratio; 

Example:

 var ratio = window.devicePixelRatio || 1; var w = screen.width * ratio; var h = screen.height * ratio; alert(screen.width); alert(screen.height); alert(w); alert(h); 

Useful link.