Is it possible to hide URL bar in iOS 9 (Safari br

2019-02-23 12:23发布

问题:

I want to hide the URL bar from my single-page application by using JavaScript.

I tried to set bigger height of the 'body' element and then perform:

window.scrollTo(0, 0);

But it doesn't work. The URL bar is still visible. How do I solve this problem?

回答1:

For iPhone, you can make your content just one pixel higher than the viewport, that will eliminate the navbar.

Working code example: 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.


回答2:

so far it seems it doesn't work on iOS 9, it stopped working after iOS 7.1.

As seen here:

Impossible to hide navigation bars in Safari iOS 7 for iPhone/iPod touch