gpt4 book ai didi

javascript - 在 iOS 8 中打开从 Web 应用程序到新 Safari 窗口的链接

转载 作者:搜寻专家 更新时间:2023-10-31 08:17:03 27 4
gpt4 key购买 nike

更新 07.14.15失去所有希望...我假设我的修复将与 javascript 相关,但我根本不知道。我当前的代码是否阻止我的 HTML target="Blanks"工作?

我正在制作一个可以下载到 iPad Mini 上的 HTML/CSS 应用程序。这是一个包含文本和图像的 30 多页简单网站。我使用这个 javascript 在应用程序中打开了我所有的 href:

$(document).ready(function(){
if (("standalone" in window.navigator) && window.navigator.standalone) {
// For iOS Apps
$('a').on('click', function(e){
e.preventDefault();
var new_location = $(this).attr('href');
if (new_location != undefined && new_location.substr(0, 1) != '#' && $(this).attr('data-method') == undefined){
window.location = new_location;
}
});
}
});

这很好,很棒。我希望该站点在其自己的窗口中运行,看起来像 native 应用程序。

现在我需要在 Safari 中打开这个 ONE 链接(它必须打开 Safari 并切换到该窗口)。

target="_blank"不起作用,或者 rel="external"

如何让链接在网络应用程序中打开,而其他链接在 Safari 中打开?

这个问题How to open Safari from a WebApp in iOS 7与我的相似,但修复对我不起作用,我现在使用的是 iOS 8。

最佳答案

我找到答案了!从这里https://gist.github.com/kylebarrow/1042026

头部的这个脚本

<script>
// Mobile Safari in standalone mode
if(("standalone" in window.navigator) && window.navigator.standalone){

// If you want to prevent remote links in standalone web apps opening Mobile Safari, change 'remotes' to true
var noddy, remotes = false;

document.addEventListener('click', function(event) {

noddy = event.target;

// Bubble up until we hit link or top HTML element. Warning: BODY element is not compulsory so better to stop on HTML
while(noddy.nodeName !== "A" && noddy.nodeName !== "HTML") {
noddy = noddy.parentNode;
}

if('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes))
{
event.preventDefault();
document.location.href = noddy.href;
}

},false);
}
</script>

和链接的标准 HTML

<a href="http://extneral" target="_blank">your link</a>

这样,web 应用程序下的本地链接仍会在同一窗口中打开,但外部 http://链接将在 Safari 中打开

关于javascript - 在 iOS 8 中打开从 Web 应用程序到新 Safari 窗口的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31299394/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com