Progressive Web Apps switching pages within the application without opening browser

-1

I have a mobile page ( link ) based on Progressive Web Apps and made using Asp.Net Core.

But I have the supposed problem:

When adding to the home screen of the mobile device by clicking on the sharing option and adding to the Home Screen as an icon as below:

Returningtothedevice'shomescreenandopeningthepagebytheiconimitatingaprogressiveapplicationiswheretheproblemarisesbecauseinsidethepageIhave2linkstootherpages,butwhenIclickonanyofthelinksitopensthebrowseralternatingbetweentheso-called"app" and Safari which is the default iPhone browser.

I would like the page change to work inside the app itself without the browser opening.

    
asked by anonymous 04.08.2017 / 07:20

1 answer

0

I solved the source below:

<!DOCTYPE html>
<html>
<head>
<title>stay standalone</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width,initial-scale=1.5,user-scalable=no">
<script type="text/javascript">
    (function(document,navigator,standalone) {
        // prevents links from apps from oppening in mobile safari
        // this javascript must be the first script in your <head>
        if ((standalone in navigator) && navigator[standalone]) {
            var curnode, location=document.location, stop=/^(a|html)$/i;
            document.addEventListener('click', function(e) {
                curnode=e.target;
                while (!(stop).test(curnode.nodeName)) {
                    curnode=curnode.parentNode;
                }
                // Condidions to do this only on links to your own app
                // if you want all links, use if('href' in curnode) instead.
                if('href' in curnode && ( curnode.href.indexOf('http') || ~curnode.href.indexOf(location.host) ) ) {
                    e.preventDefault();
                    location.href = curnode.href;
                }
            },false);
        }
    })(document,window.navigator,'standalone');
</script>
</head>
<body>
<p><a href="http://google.com/">google</a></p>
<script type="text/javascript" charset="utf-8">
    // NEVER user document.write, unless for test porposes.
    document.write('<p><a href="http://'+document.location.host+'/test/">Same domain</a></p>')
</script>
<p><a href="/test/"><span>absolute path</span></a></p>
<p><a href="test/">relative path</a></p>
<p><a href="/test?http://othersite.com">http not on beginning</a></p>
<p><a href="#test">anchor</a></p>
</body>
</html>

Retrieved from the link

    
05.08.2017 / 03:21