Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript history function not working for web page served from homescreen on iOS 6

Tags:

I've seen some other posts about iOS 6's new behaviors with Web sites saved to / launched from the home screen. On iOS 5 (and earlier), we were able to use the Javascript History function for our in-app back button. In iOS 6, however, it works if you've only been to one page in the site. But if you have more than one page that you've visited, it throws a page-not-found error. It works fine in Safari (not from the homescreen), and it works if I remove the <meta name="apple-mobile-web-app-capable" content="yes" /> tag. But then I get the ugly browser chrome that I'm trying to avoid.

I've seen similar posts about the changes to iOS 6 no longer sharing data with Safari, but I was hoping someone had run into a similar issue with the history information being stored / used for the homescreen version of the apps in iOS 6.

We're using this call: <a href="javascript:history.back();" class="back"></a>

Again, it's working fine from Safari, fine in all of the old operating systems. But it fails on iOS 6 from the homescreen when there are more than two pages that the user has clicked on.

like image 254
user1777932 Avatar asked Oct 26 '12 18:10

user1777932


1 Answers

My understanding is that if you add the apple-mobile-web-app-capable tag - it caches the page that is bookmarked to the home screen.

Any subsequent requests once the bookmark is launched will cause the safari browser to launch the url (with ugly chrome added).

You could do some basic error checking - if there is any history:

function GoBack() {
   if(history.length) {
       history.back();
       return false;
   }
   return true; //follow the regular link
}

And you really should be giving your urls a proper href value instead:

<a href="http://your_standard_url" class="back" onClick="GoBack()"></a>
like image 107
George Filippakos Avatar answered Jan 03 '23 18:01

George Filippakos