javascript 使用javascript和html隐藏iphone中的地址栏和状态栏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4030245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hide address bar and status bar in iphone using javascript and html
提问by Krishna Neeraja
I want to hide address bar and status bar in iphone because of more space. I tried this code window.scrollTo(0, 1); but this is not working in iphone. Please help me. Thanks in advance.
由于有更多空间,我想在 iphone 中隐藏地址栏和状态栏。我试过这段代码 window.scrollTo(0, 1); 但这在 iphone 中不起作用。请帮我。提前致谢。
回答by alex
For hiding the title bar, you need a setTimeout()(apparently).
要隐藏标题栏,您需要一个setTimeout()(显然)。
window.onload = function() {
setTimeout(function() { window.scrollTo(0, 1) }, 100);
};
回答by Andy G
This is by far the most comprehensive post I have seen on this subject:
这是迄今为止我在这个主题上看到的最全面的帖子:
http://mobile.tutsplus.com/tutorials/mobile-web-apps/remove-address-bar/
http://mobile.tutsplus.com/tutorials/mobile-web-apps/remove-address-bar/
Go there, it explains everything and should cover any issues you may have, as just doing window.scrollTo(0, 0); is not enough in most cases.
去那里,它解释了一切,应该涵盖你可能遇到的任何问题,就像做 window.scrollTo(0, 0); 大多数情况下是不够的。
回答by Adam Huddleston
This way works for me everytime...
这种方式每次都对我有用......
Place the below script in the the header:
将以下脚本放在标题中:
<!-- Remove Web Address Bar Cross Platform -->
<script type="text/javascript">
function hideAddressBar()
{
if(!window.location.hash)
{
if(document.height < window.outerHeight)
{
document.body.style.height = (window.outerHeight + 50) + 'px';
}
setTimeout( function(){ window.scrollTo(0, 1); }, 50 );
}
}
window.addEventListener("load", function(){ if(!window.pageYOffset){ hideAddressBar(); } } );
window.addEventListener("orientationchange", hideAddressBar );
</script>
As far as I can tell, the combination of extra height added to the page and the scrollTo() statement make the address bar disappear.
据我所知,添加到页面的额外高度和 scrollTo() 语句的组合使地址栏消失。
Hope this helps.. :)
希望这可以帮助.. :)
回答by Conal Trinitrotoluene Da Costa
Do you need to do it in javascript? Personally, I'd just add a meta tag:
你需要用javascript来做吗?就个人而言,我只是添加一个元标记:
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,minimal-ui">
回答by Erik
Try something like
尝试类似
window.onload = function() {
window.scrollTo(0, 0);
};
This should hide the address bar.
这应该隐藏地址栏。
回答by Mic
Try to put at the very end of the BODYtag a script with the scrollcommand.
尝试在BODY标签的最后放置一个带有scroll命令的脚本。
<script>window.scrollTo(0,1)</script>
It works well in our app on both iPhone and android.
它在我们的 iPhone 和 android 应用程序中运行良好。

