【问题标题】:iOS 9 Safari Web App links open in SafariiOS 9 Safari Web App 链接在 Safari 中打开
【发布时间】:2016-01-05 03:42:42
【问题描述】:

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

我有这个代码作为修复:

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

但我的链接仍然在单独的 Safari 窗口中打开,而不是在网络应用程序本身中打开。

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

提前致谢

【问题讨论】:

  • 啊!我有一个正在生产的网络应用程序,还没有在 iOS 9 上检查它。我现在正在更新我的 iPhone,所以我可以检查 Apple 没有为我挖坑……如果我有同样的问题和/或找到解决方案,我会告诉你。
  • 嗯,我的网络应用程序仍然可以正常工作!它使用与您相同的基本技术,所以我不确定为什么您的不再有效。它在页面加载后运行,对吧?

标签: ios mobile web web-applications safari


【解决方案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>

【讨论】:

    猜你喜欢
    • 2011-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    • 2016-12-09
    • 2020-04-22
    相关资源
    最近更新 更多