How can I open an external link in Safari not the app's UIWebView?

后端 未结 10 1391
甜味超标
甜味超标 2020-11-28 10:47

I have a Phonegap (cordova) application where I want to load some external webpages within the phonegap WebView and I have other external webpages that I want to load in saf

相关标签:
10条回答
  • 2020-11-28 11:12

    Tested on cordova 2.4 + iOS

    use "_system" and no need to update any configuration

    http://docs.phonegap.com/en/2.3.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser

    target: the target to load the URL in (String) (Optional, Default: "_self")

    _self - opens in the Cordova WebView if url is in the white-list, else it opens in the InAppBrowser _blank - always open in the InAppBrowser _system - always open in the system web browser

    0 讨论(0)
  • 2020-11-28 11:12

    This works for me it helps alot

    -(void)viewDidLoad
    {
       [super viewDidLoad];
        ////////////////////////
        NSString *urlAddress = @"http://www.playbuzz.org/";
        //NSURL *myURL = [NSURL URLWithString:urlAddress];
        myWebview.delegate = (id)self;
       [myWebview loadRequest:[NSURLRequest requestWithURL:[NSURL     URLWithString:urlAddress]]];
    }
    
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    
    
        //  open External Links (not beginning with www.playbuzz.org/ in Safari.app
        if (
            (navigationType == UIWebViewNavigationTypeLinkClicked) &&
            ( ![[[request URL] absoluteString] hasPrefix:@"http://www.playbuzz.org/"])
            ) {
    
            [[UIApplication sharedApplication] openURL:request.URL];
            return NO;
        }
    
       //open Internal links in uiwebview
       return YES;
    }`
    
    0 讨论(0)
  • 2020-11-28 11:14

    if you want to open an external url in safari, I think this is useful:
    This is the %100 guaranteed solution if you are using phonegap - Tested in ios6.
    to open external url in safari do following:

    1-add your link in External Host (white list). e.g http://google.com
    2-in Cordova.plist or Phonegap.plist, change "OpenAllWhitelistURLsInWebView" from "Yes" to "No"
    3-in your application add (target="_blank") to your link
    example

        <a href="http://google.com" target="_blank">Google.com</a>
    


    Thank you.

    0 讨论(0)
  • 2020-11-28 11:19

    You can (as of phonegap 1.5.0) use :

    <a href="some://external/url" target="_blank">Click Me</a>
    

    This should cause phonegap to launch the native browser.

    I think what user868766 was referring to was that for the above to work you need the external url to be on the whitelist. The app I have been working on opened the source of news stories in the native browser so we used * in the whitelist to ensure we didnt rule out any sources.

    Hope that helps.

    0 讨论(0)
提交回复
热议问题