admin管理员组文章数量:1323335
I am working on a mobile app and I need to get the correct browser inner height for it.
I am currently using
$(window).height()
to calculate the height. this works fine on the iphone/ipad
When I booted up a Galaxy S2 running android 2.3.5
I started to get some strange results...
The first time the page loads and $(window).height()
is called on
$().ready(function(){...
I get the correct results (regardless of the phone being vertical or horizontal)
As soon as I rotate the phone into a horizontal position it reports back the correct height
the issue happens when rotating the phone from horizontal to vertical
The Phone reports back a pletely incorrect height value
Now I tried using these values to see if any of the values were correct
screen.height
screen.availHeight
but still the same results
I am using this method to detect rotation
var previousOrientation = 0;
var checkOrientation = function(){
if(window.orientation !== previousOrientation){
previousOrientation = window.orientation;
// orientation changed, do your magic here
}
};
window.addEventListener("resize", checkOrientation, false);
window.addEventListener("orientationchange", checkOrientation, false);
// (optional) Android doesn't always fire orientationChange on 180 degree turns
setInterval(checkOrientation, 2000);
I am working on a mobile app and I need to get the correct browser inner height for it.
I am currently using
$(window).height()
to calculate the height. this works fine on the iphone/ipad
When I booted up a Galaxy S2 running android 2.3.5
I started to get some strange results...
The first time the page loads and $(window).height()
is called on
$().ready(function(){...
I get the correct results (regardless of the phone being vertical or horizontal)
As soon as I rotate the phone into a horizontal position it reports back the correct height
the issue happens when rotating the phone from horizontal to vertical
The Phone reports back a pletely incorrect height value
Now I tried using these values to see if any of the values were correct
screen.height
screen.availHeight
but still the same results
I am using this method to detect rotation
var previousOrientation = 0;
var checkOrientation = function(){
if(window.orientation !== previousOrientation){
previousOrientation = window.orientation;
// orientation changed, do your magic here
}
};
window.addEventListener("resize", checkOrientation, false);
window.addEventListener("orientationchange", checkOrientation, false);
// (optional) Android doesn't always fire orientationChange on 180 degree turns
setInterval(checkOrientation, 2000);
Share
Improve this question
asked Oct 20, 2011 at 15:37
samcconesamccone
10.9k7 gold badges44 silver badges50 bronze badges
1 Answer
Reset to default 7Screen size and innerHeight in the Android browser is really f.u.b.a.r. Especially in bination with a bug that sometimes cause the WebView not to resize when closing the keyboard. The most sane property I've found for Android is window.outerHeight. On Android it usually reports screen height minus status bar height. Doesn't do the same on iOS though, so you might need to do some browser sniffing ;(
本文标签: How to get the correct android available screen height of the browser in javascriptStack Overflow
版权声明:本文标题:How to get the correct android available screen height of the browser in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742136889a2422409.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论