我有一个问题,我创建了一个 Angular PWA,我的应用程序现在使用auth0-lock作为其身份验证。我的问题是..例如,当您单击单个登录选项(例如Google)时,您就退出了PWA并进入 Safari ,有什么办法可以防止这种情况发生?

我试图将这段代码放在我的index.html中

<!-- Prevent app from opening new safari page -->
<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>

但这似乎不起作用,我已经看到了其他一些可以防止这种情况的JavaScript hack,但我仍然没有找到可以在我的angular应用程序中工作的javascript吗?

有人对这个有经验么??

谢谢

最佳答案

它不是Angular而是PWA所特有的。在新的PWA manifest rules之后,Apple更改了iOS 11.3中的行为。

这个问题是已知的,是Apple will be working on it

不幸的是,这意味着在iOS 11.3的PWA中没有太多事情要做……

关于angular - 如何防止PWA在新的Safari窗口中打开链接和Auth0单点登录身份验证,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50635229/

10-10 22:19