简体   繁体   中英

iPhone Safari Web App opens links in new window when using javascript:history.go(-1)

I'm trying to get links in a iPhone standalone web app to open inside the web app instead of safari.

I have found this thread iPhone Safari Web App opens links in new window which helped me a lot. I have used the answer by rmarscher

<script>(function(a,b,c){if(c in b&&b[c]){var d,e=a.location,f=/^(a|html)$/i;a.addEventListener("click",function(a){d=a.target;while(!f.test(d.nodeName))d=d.parentNode;"href"in d&&(d.href.indexOf("http")||~d.href.indexOf(e.host))&&(a.preventDefault(),e.href=d.href)},!1)}})(document,window.navigator,"standalone")</script>

The problem I'm having is when my app uses a link with javascript:history.go(-1). If I click a link after clicking history.go(-1), it will open in safari instead of the web app.

Can someone please look at the code and see if there is a solution to this problem?

Unfortunately, if the web app is being used in the "app mode", it was accessed from the home page and there is no default Apple nav bar, then the JavaScript history api will not work. You must use a "direct link" and link to the actual page. The script you have is making it so when someone clicks a link on your site in "app mode" that it not to an "external" site, iOS will open the link still in "app mode".

"app mode" is also known as "standalone mode".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM