Search code examples
iphoneiosmobilesafarimobile-safari

Can the url for the "Add to home screen" on iPhone Safari be customized?


The "add to home screen" shows up on all pages of a site, and I want the URL to be the homepage that gets saved.

For example on this page: http://www.domain.com/category/page.html

Is it possible for the "Add to home screen" to save this url: http://www.domain.com

Any help would be greatly appreciated.


Solution

  • I found a sort-of workaround to this. You can detect that you were launched from the home page via window.navigator.standalone and based upon that potentially redirect.

    Also, I have done a little testing and found that on the latest iOS, different user agents are reported to the server, which opens the possibility of a faster redirect. I can't find any information about whether this has always been the case.

    Launch from home page:

    Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) 
    AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10A523
    

    Mobile Safari:

    Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) 
    AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25
    

    If your page gets most of its content via AJAX or you notice the different user-agent on the server it might be possible to skip the redirect and just act "as if" you were at another URL, since in standalone mode the URL is invisible anyway. I'm investigating this but haven't got far enough to say whether it will burn you or not.

    Also note that the user's choice of URL to mark as an app may be meaningful, but I'll leave that to your own UX judgment.