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

5

25

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.

Snowman answered 4/6, 2012 at 20:11 Comment(1)
I do not think this is possible.Outgeneral
P
11

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.

Priggish answered 30/11, 2012 at 0:25 Comment(0)
C
5

A combination of both WrightsCS and svachalek Answers - You can't "Add to home screen" a remote page. However, you can redirect from the page after it has been added to the home screen.

All you need to do is use this simple javaScript:

if ('standalone' in window.navigator && window.navigator.standalone){ //checks if you're in app mode

  window.location = 'http://www.example.com';  //the URL you want to refer to

}

Make sure you add this html code to your page:

<meta name="apple-mobile-web-app-capable" content="yes">
Clishmaclaver answered 13/10, 2014 at 9:57 Comment(0)
D
1

No, without being jailbroken (and there is nothing that I know of that achieves this), there is no way to edit the actual URL.

Apple restricts this for at least one reason I can think of Security. Editing the URL would allow people to use javascript, which would inevitably lead to malware.

Doughty answered 4/6, 2012 at 20:32 Comment(3)
I'm always naive when it comes to security tricks but this is one of those cases where it seems like in the naive case, it can only be edited by the application provider, whom you are already trusting, and in the evil XSS case there are already so many worse things they can do to you that this one isn't particularly interesting. Or is it?Priggish
It could be done without javascript if there was a meta-tag for it. It could just be something like <meta name="apple-mobile-web-app-url" content="my.domain.com/webapp/" />Playmate
I've tried this meta tag. but it does not work as expectedBarrera
S
0

I got this to work for my purpose of populating the URL of a "share" bookmark on iPhone:

history.pushState('','','/');

This worked since I only needed to cut the URL to the home domain. (And I used document.title="newName" to set the screen name of the bookmark icon.)

Sedimentary answered 12/6, 2022 at 15:45 Comment(0)
L
0

This didn't exist back when the question was asked, but the start_url field in the manifest allows this:

https://developer.mozilla.org/en-US/docs/Web/Manifest/start_url

Unfortunately this doesn't allow dynamic control, since the manifest will usually be fetched at the start. For example, it doesn't allow having it remember the search the user was on but remove the page number, so the saved search doesn't start three pages down when it's opened later.

Laryngitis answered 2/1, 2023 at 23:12 Comment(1)
Somebody gave an answer pointing to the manifest years ago and it was deleted by a moderator, even though it was the straightforward, correct answer to the question. That seems like some really confused priorities, and makes me wonder how many people searched their way to this question and didn't get the answer they needed as a result.Laryngitis

© 2022 - 2024 — McMap. All rights reserved.