admin管理员组文章数量:1314216
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.
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.
Share Improve this question edited May 23, 2017 at 11:59 CommunityBot 11 silver badge asked Jul 8, 2015 at 17:18 AnGrAnGr 1011 gold badge1 silver badge8 bronze badges1 Answer
Reset to default 5I found the answer! From here https://gist.github./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 pulsory 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
本文标签: javascriptOpen a link from web app to new Safari window in iOS 8Stack Overflow
版权声明:本文标题:javascript - Open a link from web app to new Safari window in iOS 8 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741931577a2405604.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论