臭虫的Android网络浏览器:地址栏隐藏内容 [英] Bug in Android web browser: address bar hides content
问题描述
所以,我醉在web-app库尔急救,而我从构建Android原生应用程序构建Web应用程序的切换。
So, I've drunk the web-app kool-aid, and I'm switching from building Android native apps to building web apps.
但我有在Android浏览器的地址栏(更新:具体而言,我运行的是Android 2.3.3的HTC Desire Z,我不知道有多少其他版本的影响):真的不好的问题。
But I'm having really bad problems on Android browsers with the address bar (update: specifically, my HTC Desire Z running Android 2.3.3, I'm not sure how many other versions it affects):
- 问题1:当加载页面时,地址栏隐藏
顶〜含量30像素。 (为什么地球上它做到这一点?!) - 问题2:
在某些情况下,地址栏将不会消失 - 出现这种情况的
我在肖像当连接速度很慢。
因此,在某些情况下,在地址栏中永久隐藏内容的顶部30像素。这是严重损坏。
So on some occasions, the address bar hides the top 30px of content permanently. This is seriously broken.
我借了一些code <一个href=\"http://stackoverflow.com/questions/4068559/removing-address-bar-from-browser-to-view-on-android\">another StackOverflow的问题来尝试解决这个问题:
I borrowed some code from another StackOverflow question to try to fix this:
if (navigator.userAgent.match(/Android/i)) {
window.scrollTo(0,0); // reset in case prev not scrolled
var nPageH = $(document).height();
var nViewH = window.outerHeight;
if (nViewH > nPageH) {
nViewH = nViewH / window.devicePixelRatio;
$('BODY').css('height',nViewH + 'px');
}
window.scrollTo(0,1);
}
但它似乎并不可靠地工作 - 更何况,这是一个可怕的解决方案。我该怎么办?
But it doesn't seem to work reliably - not to mention that it's a horrible solution. What can I do?
推荐答案
下面的非jQuery的解决方案,可以立即删除地址栏不滚动。此外,当你旋转浏览器的定位它的工作原理。
Here's the NON-jQuery solution that instantly removes the address bar without scrolling. Also, it works when you rotate the browser's orientation.
function hideAddressBar(){
if(document.documentElement.scrollHeight<window.outerHeight/window.devicePixelRatio)
document.documentElement.style.height=(window.outerHeight/window.devicePixelRatio)+'px';
setTimeout(window.scrollTo(1,1),0);
}
window.addEventListener("load",function(){hideAddressBar();});
window.addEventListener("orientationchange",hideAddressBar());
应该与iPhone同样的工作,但我无法进行测试。
It should work with the iPhone also, but I couldn't test this.
这篇关于臭虫的Android网络浏览器:地址栏隐藏内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!