Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to detect mobile browser screen width?

i used screen.width to get the width of the browser. it worked fine with iphone safari but didn't work in android phone(it showed 800 width for android browser).

Is there any compatible way to get the screen width. I dont want to use UserAgent to check if its mobile browser. would like to use a javascript for that and logic should include screen width.

like image 912
user378132 Avatar asked Dec 14 '11 16:12

user378132


1 Answers

It's know issue - see here

When page first loads the screen.width and screen.height are wrong. Try a timeout like this:

setTimeout(CheckResolution, 300);

Where CheckResolution is your function.

like image 195
SlavaNov Avatar answered Oct 04 '22 05:10

SlavaNov