4
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />     

$('#btn-fb-share').click(function() {
        $('#btn-fb-share').attr("disabled", "disabled");
        window.open(url,"Mywindow","location=yes,menubar=yes");
    });

在我的 Ipad 上(我在主屏幕上创建了网站的快捷方式),链接不会在新窗口(Safari)中打开。我该如何解决这个问题?在我的电脑上,链接在新窗口中正确打开。

编辑:我会尽量解释清楚。

发生了什么:我的 Web 应用打开的 URL 与我的应用在同一个窗口中。 流程是

应该发生的是:Facebook 页面在 safari 的新选项卡中打开。(如果我通过 safari 而不是我的网络应用程序打开我的网站,我可以证明这一点。)

流程应该是

我希望你现在能看到不同之处。我需要在 Safari 中的新选项卡中打开我的链接。但现在它一直在我的窗口中打开它,我没有“返回按钮”。

两张图的唯一区别是。第一张图片是保存在我的主屏幕上的网站。第二张图片是直接在 Safari 中打开的网站。

4

1 回答 1

5

进行了谷歌搜索,并在 macrumors.com上找到了这个帖子,并解释了同样的问题:

对于我想在 WebApp 中打开而不在 Safari 中打开的链接,我使用这个:

<a onclick="parent.location='http://url.com/page.html'">Link</a>

对于我想在 Safari 中打开的链接,我使用标准的 HTML 链接:

<a href="http://url.com/another_page.html">Link</a>

所以我又做了一次谷歌搜索,发现如何检测你是否在 JavaScript 中使用 iOS:http: //forrst.com/posts/JavaScript_iOS_Detection-Ofa

这是我的解决方案:

var url = "http://www.google.com/";

// Get the user agent string
var deviceAgent = navigator.userAgent;
// Set var to iOS device name or null
var ios = deviceAgent.toLowerCase().match(/(iphone|ipod|ipad)/);

$('#btn-fb-share').click(function() {

    if (ios) {
        // This is the line that matters
        $(this).attr('href', url);
    } else {
        // Your code that works for desktop browsers
        $('#btn-fb-share').attr("disabled", "disabled");
        window.open(url,2789432749274249,"location=yes,menubar=yes");
    }
});

我在桌面上的 Chrome 中以及通过 Safari 和主屏幕 WebApp 在 iOS 上对其进行了测试。这是我的工作测试的链接:http: //flackend.com/other/ios-test/

请注意,您需要将链接设置target_blank以在 iOS 上的 Safari 的新选项卡中打开它(如果您在 Safari 应用程序中打开它,则不是来自 WebApp 实例)。您可以直接在 HTML 标记中进行设置,也可以使用 jQuery 使用attr.

于 2012-07-18T16:45:14.323 回答