微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 检测如果iOS正在使用webapp

我想知道是否可以检测iOS用户是否正在使用webapp,或者只需使用Safari浏览器访问正常方式.

我想要实现的原因是,当用户点击链接时,在iOS webapp上,他将被重定向到Safari浏览器.所以我使用以下解决方法让他留在webapp(防止切换到safari浏览器).

$( document ).on("click",".nav ul li a",function( event ){

        // Stop the default behavior of the browser,which
        // is to change the URL of the page.
        event.preventDefault();

        // Manually change the location of the page to stay in
        // "Standalone" mode and change the URL at the same time.
        location.href = $( event.target ).attr( "href" );

        }
    );

但是我想要这种解决方法只有当用户使用webapp时才会发生,我希望它是webapp用户的条件.所以没有在认的safari浏览器.

解决方法

你必须通过使用一些javascript来检测:
<script>
if (
    ("standalone" in window.navigator) &&       // Check if "standalone" property exists
    !window.navigator.standalone                // Test if using standalone navigator
    ){

    // .... code here ....
}
</script>
</head>

可以在这里找到:Determine if site is open as web app or through regular safari on ipad?

答案中使用的来源是THIS.

原文地址:https://www.jb51.cc/js/153994.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐