简体   繁体   English

iOS 9 Safari Web App链接在Safari中打开

[英]iOS 9 Safari Web App links open in Safari

I have a mobile web app capable safari app for iPhone running on iOS 9. There's only one problem: the fix for opening links IN the mobile web app, doesn't seem to work anymore. 我有一个可在iOS 9上运行的,支持iPhone的移动网络应用程序的野生动物园应用程序。只有一个问题:在移动网络应用程序中打开链接的修复似乎不再起作用。

I have this code as a fix: 我有此代码作为修复:

<script type="text/javascript">
$('a').click(function() {
    if(!$(this).hasClass('noeffect')) {
        window.location = $(this).attr('href');
        return false;
    }
});
</script>

But still my links are opening in a separate safari window, in stead of in the web app itself. 但是我的链接仍然在单独的野生动物园窗口中打开,而不是在Web应用程序本身中打开。

Working demo can be seen at: http://www.dennisprins.nl/project6 , when you hit the "Toevoegen"-dashed box, you'll see what happens when you added the page to your homescreen. 可以在以下网址查看工作演示: http : //www.dennisprins.nl/project6 ,单击“ Toevoegen”虚线框时,您会看到将页面添加到主屏幕时会发生什么。

Thanks in advance 提前致谢

Try this 尝试这个

 <script>
    (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;
                }
                // Conditions 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM