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

时间:2015-10-07 18:51:12

标签: ios mobile web web-applications safari

我在iOS 9上运行的iPhone有一个支持移动网络应用程序的Safari应用程序。只有一个问题:在移动网络应用程序中打开链接的修复程序似乎不再有效。< / p>

我将此代码作为修复:

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

但我的链接仍然在一个单独的safari窗口中打开,而不是在Web应用程序本身。

可以在http://www.dennisprins.nl/project6看到工作演示,当您点击“Toevoegen&#34; -dashed”框时,您会看到将页面添加到主屏幕时会发生什么。< / p>

提前致谢

1 个答案:

答案 0 :(得分:1)

试试这个

 <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>
相关问题