Launch mobile safari from a full-screen web application on iPhone

I asked this question in several ways and can only find answers in the context of using PhoneGap or jQuery mobile. However, I am not using either ... just the old html and javascript.

I am trying to start a mobile safari from a full-screen web application using window.open () ... not an inline anchor. No matter what I do, the URL opens in the web application, not in Safari. Anyone have any suggestions?

Thank.

+5
source share
6 answers

, . - iOS , jQuery, , , . jQuery, , DOM.

if (window.navigator.standalone) {
  var $a = $('<a href="' + url + '" target="_blank"/>');
  $("body").append($a);

  var a = $a.get(0);

  var mouseEvent = a.ownerDocument.createEvent('MouseEvents');
  mouseEvent.initMouseEvent('click');
  a.dispatchEvent(mouseEvent);

  $a.remove();
}
else {
  window.open(url, '_blank');
}
+2

iOS 4.3, , , - <div> <a target="_blank"> . Safari.

+1

PhoneGap URL- WebView . JS WebView. URL- Safari, PhoneGap, URL- .

PhoneGap [projectname] AppDelegate.m... , [projectname]/Classes.

mustStartLoadWithRequest, . , HTTP HTTPS Safari ( http://solutions.michaelbrooks.ca/2011/02/15/open-external-links-in-safariapp/):

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = [request URL];

    // Intercept the external http requests and forward to Safari.app
    // Otherwise forward to the PhoneGap WebView
    if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
        [[UIApplication sharedApplication] openURL:url];
        return NO;
    }
    else {
        return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
    }
}
+1

window.openNative()?

0

HREF? Safari webapp.

0

HTML, Safari ( Javascript), :

var a = document.createElement("a");
a.setAttribute('href', facebook);
a.setAttribute('target', '_blank');
a.click();
0
source

All Articles