Can the url for the “Add to home screen” on iPhone

2019-01-17 11:40发布

问题:

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.

回答1:

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.



回答2:

A combination of both WrightsCS and svachalek Answers - You can't add to home screen a remote page, however, you can redirect 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.domain.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">


回答3:

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.