<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");
});
Run Code Online (Sandbox Code Playgroud)
在我的 Ipad 上(我在主屏幕上创建了网站的快捷方式),该链接不会在新窗口 (Safari) 中打开。我该如何解决这个问题?在我的 PC 上,链接在新窗口中正确打开。
编辑:我会尝试更清楚地解释它。
发生了什么:我的 Web 应用程序在与我的应用程序相同的窗口中打开 url。

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

我希望你现在能看出区别。我需要在 Safari 中的新选项卡中打开我的链接。但现在它一直在我的窗口中打开它,在那里我没有“返回按钮”。
两张图片的唯一区别是。第一张图片是保存在我的主屏幕上的网站。第二张图是在Safari中直接打开的网站。
进行了谷歌搜索,并在 macrumors.com上找到了这个帖子,其中解释了同样的问题:
对于我想在 WebApp 中打开而不在 Safari 中打开的链接,我使用这个:
<a onclick="parent.location='http://url.com/page.html'">Link</a>
Run Code Online (Sandbox Code Playgroud)
对于我想在 Safari 中打开的链接,我使用标准的 HTML 链接:
<a href="http://url.com/another_page.html">Link</a>
Run Code Online (Sandbox Code Playgroud)
所以我做了另一个谷歌搜索,找到了如何检测你是否在 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");
}
});
Run Code Online (Sandbox Code Playgroud)
我在台式机上的 Chrome 中进行了测试,在 iOS 上通过 Safari 和主屏幕 WebApp 对其进行了测试。这是我的工作测试的链接:http : //flackend.com/other/ios-test/
请注意,您需要设置链接的target,以_blank它在Safari浏览器中的一个新的选项卡上的iOS(不是从Web应用程序来说,如果你在Safari浏览器应用程序打开它)打开。您可以直接在 HTML 标记中进行设置,也可以使用 jQuery 进行设置attr。
| 归档时间: |
|
| 查看次数: |
15443 次 |
| 最近记录: |