【问题标题】:redirect iOS webApp user to Safari?将 iOS webApp 用户重定向到 Safari?
【发布时间】:2014-03-26 22:15:29
【问题描述】:

我正在开发一个网站。

iPhone 用户可以“保存到主屏幕”我的网站。这样做会在 iPhone 的主屏幕上放置一个图标,以便用户可以作为 WebApp 访问我的网站(全屏模式,Safari 视图)。

我正在尝试将 webApp 用户重定向到普通 Safari。我不希望用户以 webApp 模式查看我的网站。

这是代码:

window.onload=function(){
    if (navigator.standalone) {
        console.log ('Running iOS webApp, lets send user to Safari');
        window.location.href = "http://www.urlToWebsite.com";
    } else {
        console.log ('Running in a normal browser');
    }
};

从每个人在线发布的内容来看,在 iOS webApp“模式”中打开的链接会重定向到 Safari。

但是,在这种情况下,当我使用 javascript“单击”链接时,不会发生重定向到 Safari 的情况。相反,webApp 会重新加载到位。

如何成功重定向到 Safari?

【问题讨论】:

  • 你需要真正的用户点击,没有欺骗 iOS...

标签: javascript ios web-applications iphone-standalone-web-app


【解决方案1】:

如果用户单击链接,您只能从 Web 应用程序重定向回 Safari,因此您需要做的就是触发链接单击。

这是您将被重定向回 Safari 的基本页面的代码。

<!DOCTYPE html>
<html>
<head>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>iOS Web App Test</title>
</head>
<body>
<script>
    if (window.navigator.standalone == true) {
        document.write('You are viewing this website as an iOS web App');
        document.write('<a href="http://www.urlToWebsite.com/?a" id="redirect-link" style="display: none;">Safari Website</a>');
        document.getElementById("redirect-link").click();
    } else {
        document.write('You are viewing this website in Safari.');
    }
</script>
</body>
</html>

您会注意到重定向链接末尾添加了一个“?a”,因为 iOS 网络应用不会重定向到同一页面。

【讨论】:

    猜你喜欢
    • 2013-06-20
    • 1970-01-01
    • 1970-01-01
    • 2018-08-23
    • 2016-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多