ratchet icon indicating copy to clipboard operation
ratchet copied to clipboard

Links open in new browser when it is added to the home screen

Open newpen opened this issue 10 years ago • 14 comments

I am using iOS6, after adding the ratchet template to the home screen and clicking the links in it, the links open in a new safari browser. Any method to make it to load on the same page?

newpen avatar Jul 12 '14 07:07 newpen

do you import ratchet.js?

huang-x-h avatar Jul 15 '14 01:07 huang-x-h

I now try to do it with http://jakiestfu.github.io/Snap.js/demo/apps/ratchet/template.html Still the same problem. Looking at the source code, it should have imported ratchet.js.

newpen avatar Jul 15 '14 06:07 newpen

Same problem here when using push.js on iOS7.

lesander avatar Aug 01 '14 11:08 lesander

Same problem for me. It only happens when you click very fast on 2 or more links. Android (Chrome) works fine.

philipgiuliani avatar Oct 09 '14 08:10 philipgiuliani

Same problem for me.

keepinmind avatar Oct 09 '14 08:10 keepinmind

Same. It seems to only happen sporadically. Any thoughts on where to look for a bug — either on my own codebase or on ratchet's?

leonsas avatar Oct 20 '14 06:10 leonsas

I think you should search on ratchets codebase (espacially page.js)

philipgiuliani avatar Oct 20 '14 06:10 philipgiuliani

It only happens on iOS. Android works fine.

leonsas avatar Oct 20 '14 16:10 leonsas

This will solve it 100% for iOS (Tested with iOS 8)

<head>
    <title>Stay Standalone!</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="white">
    <meta name="apple-mobile-web-app-title" content="Web App title to override title element name">

    <!-- With credit to Irae Carvalho - https://gist.github.com/kylebarrow/1042026#comment-37145 -->
    <script type="text/javascript">
        (function(document,navigator,standalone) {
            // Prevents links in 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;
                    }
                    // If you want this to affect all links and not just your app, 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>

JayHoltslander avatar Oct 20 '14 19:10 JayHoltslander

Thanks for the fix, will try it out these days.

philipgiuliani avatar Nov 03 '14 11:11 philipgiuliani

@JayHoltslander Doesn't seem to solve it for me.

leonsas avatar Nov 03 '14 17:11 leonsas

@JayHoltslander worked! Thanks!

tlyda avatar Jan 28 '15 22:01 tlyda

Oh forgot to say that it also worked for me

philipgiuliani avatar Jan 28 '15 22:01 philipgiuliani

It works, thanks!

kamihouse avatar May 24 '16 22:05 kamihouse