在iOS 8中打开从Web应用程序到新Safari窗口的链接 [英] Open a link from web app to new Safari window in iOS 8
问题描述
失去所有希望...
我假设我的修复将与javascript相关,但我根本不知道它。我当前的代码是否停止了我的HTML目标=空白?
我正在制作一个HTML / CSS应用程序,它是在iPad Mini上下载的。这是一个简单的30+页面,包含文字和图片。我使用这个javascript来让我所有的href在应用中打开:
$(document).ready(function(){$ ((standalonein window.navigator)&& window.navigator.standalone){
//对于iOS Apps
$('a')。on('click' ,函数(e){
e.preventDefault();
var new_location = $(this).attr('href');
if(new_location!= undefined& new_location .substr(0,1)!='#'&& $(this).attr('data-method')==未定义){
window.location = new_location;
}
});
}
});
这很好,很好。我希望网站能够在自己的窗口中工作,看起来像一个本地应用程序。
现在我需要在Safari中打开这个链接(它必须打开Safari并切换到该窗口)。
target =_ blank不起作用,或者rel =external
您如何在Web应用程序中打开链接以及其他链接在Safari中打开?
这个问题如何从iOS 7中的WebApp打开Safari 与我的类似,但该修补程序对我无效,而且我在iOS 8中现在。
我找到了答案!从这里 https://gist.github.com/kylebarrow/1042026
头文件中的脚本
< script>
//在独立模式下的移动Safari
if((在window.navigator中的standalone)&& window.navigator.standalone){
//如果你想为防止独立Web应用程序中的远程链接打开Mobile Safari,请将远程更改为true
var noddy,remotes = false;
document.addEventListener('click',function(event){
noddy = event.target;
//直到我们点击(noddy.nodeName!==A&& noddy.nodeName!==HTML){$();} b $ b 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:// extneraltarget =_ blank>您的链接< / a>
通过这种方式,web应用下的本地链接仍然在同一个窗口中打开,但外部http:/ /链接将在Safari中打开
UPDATE 07.14.15 Losing all hope... I'm assuming my fix will be javascript related but I don't know it at all. Is my current code stopping my HTML target="Blanks" from working?
I'm making an HTML/CSS app that's downloaded on an iPad Mini. It's a simple 30+ page site with text and images. I used this javascript to make all my href's open inside the app:
$(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;
}
});
}
});
Which is fine and great. I want the site to work in its own window, to look like a native app.
NOW I need to make this ONE link open up in Safari (it would have to open Safari and switch to that window).
target="_blank" doesn't work, or rel="external"
How do you have links that open inside a web app AND other links open in Safari?
This question How to open Safari from a WebApp in iOS 7 is similar to mine, but the fix won't work for me, and I'm in iOS 8 now.
I found the answer! From here https://gist.github.com/kylebarrow/1042026
This script in the head
<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>
and standard HTML for the links
<a href="http://extneral" target="_blank">your link</a>
This way local links under the web apps still open in the same window, but the external http:// links will open in Safari
这篇关于在iOS 8中打开从Web应用程序到新Safari窗口的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!