是否可以使用 JavaScript 在 iOS 9(Safari 浏览器)中隐藏 URL 栏?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32952980/
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
Is it possible to hide URL bar in iOS 9 (Safari browser) by using JavaScript?
提问by Aircraft5
I want to hide the URL bar from my single-page application by using JavaScript.
我想使用 JavaScript 从我的单页应用程序中隐藏 URL 栏。
I tried to set bigger height of the 'body' element and then perform:
我尝试设置更大的“body”元素高度,然后执行:
window.scrollTo(0, 0);
But it doesn't work. The URL bar is still visible. How do I solve this problem?
但它不起作用。URL 栏仍然可见。我该如何解决这个问题?
采纳答案by Patrick Fabrizius
For iPhone, you can make your content just one pixel higher than the viewport, that will eliminate the navbar.
对于 iPhone,您可以使您的内容仅比视口高一个像素,这将消除导航栏。
Working code example: http://pastebin.com/16s8Xvbw
工作代码示例:http: //pastebin.com/16s8Xvbw
Caveats:
注意事项:
- Only works in landscape, and when flipping from portrait to landscape - if user enters the page in landscape, he/she must flip to portrait and back to landscape.
- If the user touches near top / bottom, navbar will re-appear.
- Does not work on iPad at all.
- 仅适用于横向,并且当从纵向翻转到横向时 - 如果用户以横向方式进入页面,他/她必须翻转到纵向并返回横向。
- 如果用户触摸顶部/底部附近,导航栏将重新出现。
- 根本不适用于 iPad。
回答by Luciano
so far it seems it doesn't work on iOS 9, it stopped working after iOS 7.1.
到目前为止,它似乎不适用于 iOS 9,它在 iOS 7.1 之后停止工作。
As seen here:
如这里所见:
Impossible to hide navigation bars in Safari iOS 7 for iPhone/iPod touch