Javascript来检测手机浏览器的屏幕宽度? [英] Javascript to detect mobile browser screen width?
问题描述
我用screen.width获取浏览器的宽度。它的罚款与iPhone Safari浏览器,但是在android手机没有工作(这表明800宽度的Android浏览器)。
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).
有没有兼容的方式来获取屏幕宽度。我不想使用用户代理,以检查它的移动浏览器。想使用JavaScript为和逻辑应包括屏幕宽度。
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.
推荐答案
这是认识问题 - 看<一href="http://$c$c.google.com/p/android/issues/detail?id=12455&q=javascript%20width&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars"相对=nofollow>这里
It's know issue - see here
在第一次加载页面的 screen.width
和 screen.height
是错误的。
尝试这样的超时:
When page first loads the screen.width
and screen.height
are wrong.
Try a timeout like this:
setTimeout(CheckResolution, 300);
其中, CheckResolution
是函数。
这篇关于Javascript来检测手机浏览器的屏幕宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!