Javascript to detect mobile browser screen width?

前端 未结 5 530
执念已碎
执念已碎 2021-02-05 15:47

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 the

5条回答
  •  死守一世寂寞
    2021-02-05 16:16

    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.

提交回复
热议问题