Search code examples
mobile-websitemobile-applicationiphone-standalone-web-app

Background behavior for iOS Web App (so app doesn't restart)


I'm trying to build a mobile web app and am intrigued by the "apple-mobile-web-app-capable" option, making the app feel a lot more native.

The issue I'm having is that it's an app that lets a user browse through a bunch of content, some of which opens a new browser window outside the web app (on purpose). The problem is, when a user goes back to the web app, it re-launches and starts them from the home page.

Has anyone found a way to avoid this complete reloading process?


Solution

  • ive got it working like this:

    if(window.navigator.standalone === true) {
        var lastpage = localStorage.getItem('exitsatus');
        if (lastpage==null){
            lastpage = "index.html";
        }
        if(document.referrer.length > 0 && document.referrer.indexOf("mysite.com") != -1){
            var lastpageupdate = window.location;
            localStorage.setItem('exitsatus',lastpageupdate);      
        } else {
            window.location = lastpage;
        }
    }