Progressive Web Apps switching pages inside the app without opening browser

Asked

Viewed 241 times

-1

I have a mobile page (http://mvc-decea.azurewebsites.net) based on Progressive Web Apps and made using Asp.Net Core.

But I’m in so much trouble:

When adding to the mobile home screen by clicking on the share option and adding to the Home Screen as a conforming icon below:

inserir a descrição da imagem aqui

When returning to the home screen of the device and open the page by the icon imitating a progressive application is where the problem arises, because inside the page I have 2 links to other pages, but when I click on any of the links it opens the browser alternating between the supposed "app" and Safari which is the default iPhone browser.

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

1 answer

0

I solved with 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>

Obtained through the link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.