63

How do I hide the address bar on iPhone?

I tried two different methods so far:

  • The scroll down one pixel trick with JavaScript on page load

  • And the following meta tags:

    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" /><meta name="apple-mobile-web-app-capable" content="yes" />
    

Also this:

<meta names="apple-mobile-web-app-status-bar-style" content="black-translucent" />

I am completely confused.

PS: Oh, I forgot a really important thing: the web page itself does not overflow the browser window. It probably is the reason why the 1 pixel scrolldown trick does not work.

I can't make it bigger, since the hit thing about the design, that everyone can scroll, but this page folds... :)

4
  • 2
    If the page doesn't overflow the browser viewport, why don't you make the page body a little higher, scroll to 0,1 to hide the address bar and then disable scrolling?
    – Rengers
    Commented Nov 7, 2010 at 19:07
  • These metatags only have an effect if the app was launched via a bookmark on the home screen. More info: developer.apple.com/library/safari/codinghowtos/Mobile/…
    – xentek
    Commented Sep 23, 2013 at 21:48
  • See also stackoverflow.com/questions/37395561/…
    – rogerdpack
    Commented Oct 28, 2018 at 4:54
  • The example of above should use the 'name' attribute, instead of 'names'.
    – Bob
    Commented Jan 19, 2021 at 0:00

11 Answers 11

87

I just hit this myself. If the address bar is not hiding, the reason may simply be the page is not long enough to scroll.

When the

window.scrollTo(0,1)

is called the page MUST be longer than the window so a scrolling event can occur.

Only when the scrolling even occurs will mobile safari hide the address bar.

6
  • This should have more up-votes, you're absolutely spot on about page height. Can't scroll if there's nothing there!
    – iamkeir
    Commented Apr 16, 2012 at 12:30
  • To make it the right height, see: stackoverflow.com/questions/5206811/… Commented Jun 5, 2013 at 14:37
  • Was searching for 'hiding address bar' not working, but instead, this solved my problem of 'width=device_width' not working. +1 for that. Commented Sep 11, 2013 at 11:53
  • 8
    This does not work in my current version of Chrome or Safari.
    – swade
    Commented Jul 6, 2016 at 17:16
  • 11
    Still can't make it work. View port scroll but address bar wont hide. Tried played with timeout, pixels to scroll but nothing help. Still work for iOS11.4 for you? This is live example, code is before body. Thank you for help. vesmir.pigy.cz/list.php?p=hraj&t=pexeso
    – tom52
    Commented Jun 13, 2018 at 8:51
12

🔴 UPDATE: Apple removed support for minimal-ui in iOS 8 so this is no longer a useful answer :(


For new googlers looking into this: As of iOS 7.1 there's a new minimal-ui mode that works on mobile Safari:

minimal-ui

It's enabled by setting the minimal-ui property on the viewport:

<meta name="viewport" content="minimal-ui">

You can also use it in conjunction with other properties like so:

<meta name="viewport" content="width=device-width, minimal-ui">

Of note, there's no minimum content length requirement as there is with the scrollTo hack. There's a great overview of this new mode here. (That's where the above image comes from.) He also lists some shortcomings.

The only official documentation I could find on this is a note in Apple's iOS 7.1 release notes:

A property, minimal-ui, has been added for the viewport meta tag key that allows minimizing the top and bottom bars on the iPhone as the page loads. While on a page using minimal-ui, tapping the top bar brings the bars back. Tapping back in the content dismisses them again.

For example, use <meta name="viewport" content="width=1024, minimal-ui”>.

Of course, since this only works in iOS 7.1 and above, it's usefulness may be limited.

1
10

Unless something has changed in recent iOS versions, the scroll down trick is the only one that reliably works, I've had no issues with this version:

/mobile/i.test(navigator.userAgent) && !location.hash && setTimeout(function() {
  window.scrollTo(0, 1);
}, 1000);​

I didn't care about any other mobile platform for this particular page though, it was redirecting based on agent...you may want to change the regex to check for iPhone specifically, e.g. replace /mobile/ with /iPhone/.

2
  • This is gonna be an iphone only microsite. Thanks for the advice Nick, gonna try it ;-) Commented Nov 7, 2010 at 11:08
  • Nope, still no effect. But I think, I am doing something wrong. I attached the code you just gave me, to onload, with jquery: Commented Nov 7, 2010 at 11:17
6

I think this version is actually better. It tests to see if the user has already begun scrolling, which is an issue I noticed in my mobile project.

/Mobile/.test(navigator.userAgent) && !location.hash && setTimeout(function () {
    if (!pageYOffset) window.scrollTo(0, 1);
}, 1000);
3

You can run the function when the site content is ready instead of using timeout

addEventListener("load", function() {
    window.scrollTo(1, 0);
}, false);
3

I have been searching around on this full screen web app as well and i found this.

http://www.onlywebpro.com/2015/07/19/optimizing-full-screen-mobile-web-app-for-ios/

  1. Basically you need add the following in your header:
<meta name="viewport" content = "width = device-width, initial-scale = 1.0, minimum-scale = 1, maximum-scale = 1, user-scalable = no" />
    
//App name
<meta name="apple-mobile-web-app-title" content="App name" />

<meta name="apple-mobile-web-app-capable" content="yes">

<meta name="apple-mobile-web-app-status-bar-style" content="black" />

//APP ICONS 
<link rel="apple-touch-icon" href="/img/icon.png">

<link rel="apple-touch-icon" sizes="76x76" href="/img/icon.png">

<link rel="apple-touch-icon" sizes="120x120" href="/img/icon.png">

<link rel="apple-touch-icon" sizes="152x152" href="/img/icon.png">
  1. Open the site in Safari
  2. Tap on the "Open with" icon ( arrow pointing upwards and box below it) beside refresh button at the URL bar
  3. Select "Add to home screen"
  4. Go to the homescreen and open the "App name"
  5. Voila! website with no URL bar or navigation buttons!
1
  • FYI, some functionality, such as the ability to request a WakeLock goes away when installing web pages as apps on the home screen. Commented Sep 28, 2023 at 0:27
2

Try:

setTimeout(function () {
  window.scrollTo(0, 1);
}, 1000);

If using jQuery, put it at the end of $(document).ready();. The time-out allows for the browser to determine the height of the page...

2

In case none of these solutions work and you are running into the very narrow issue that I faced, here's what fixed it for me.

I had this in my CSS

html{position: relative; height: 100%; overflow: hidden;}

This css applies a fix to one of my pages only, so I restricted it with a condition to that page, and the address bar is now behaving correctly on all other pages.

1
  • 1
    This just locks the page length for me, eliminating scrolling. And the address bar remains. iOS 17 on iPhone 11 Pro. Commented Sep 28, 2023 at 0:26
1
<meta name="apple-mobile-web-app-capable" content="yes" />

iPhone Configuring Web Applications

1
  • 10
    This only works when a user has bookmarked the site as a home screen icon. Commented Jul 18, 2014 at 20:18
1

I think it will never be solved unless the content is more than the browser window.

Here is some code that will hide the URL on load, on orientation change, and on a touchstart (the touchstart should only be used if you have a persistent hidden URL, which is a whole other can of worms - if you don't, remove that part of the script).

if( !window.location.hash && window.addEventListener ){
    window.addEventListener("load", function() {
        setTimeout(function(){
            window.scrollTo(0, 0);
        }, 0);
    });
    window.addEventListener( "orientationchange",function() {
        setTimeout(function(){
            window.scrollTo(0, 0);
        }, 0);
    });
    window.addEventListener( "touchstart",function() {
         setTimeout(function(){
             window.scrollTo(0, 0);
         }, 0);
     });
}
-4
<meta charset="utf-8"><meta name="description" content="{MF_PLUGIN_SETTING:HOME_DESCRIPTION}"/><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1"/><meta name="apple-mobile-web-app-capable" content="yes"><meta name="mobile-web-app-capable" content="yes"> 

This is used for adding a ios web app to the homescreen without the searchbar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.