Open link from web app to new Safari window in iOS 8

UPDATE 07.14.15 Losing all hope ... I'm guessing my fix will be javascript related, but I don't know that at all. Is my current code stopping my HTML target = "Forms" from working?

I am making an HTML / CSS app loaded on iPad Mini. This is a simple site with 30+ pages of text and images. I used this javascript to open all my hrefs 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;
    }
    });
    }
    });

      

It's wonderful and great. I want the site to run in its own window to look like a native application.

NOW I need to make this ONE link open in Safari (it will need to open Safari and switch to this window).

target = "_blank" doesn't work, or rel = "external"

How do you have links opening inside a web app and other links opening in Safari?

This question How to open Safari from WebApp in iOS 7 is similar to mine, but the fix won't work for me and I'm in iOS 8 now.

+3


source to share


1 answer


I found the answer! From here https://gist.github.com/kylebarrow/1042026

This script in my 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 links

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

      

This way local links under web apps still open in the same window, but external links http: // will open in Safari

+3


source







All Articles