3

我正在使用以下https://github.com/apache/incubator-cordova-mac制作 mac os x 应用程序,但似乎我无法打开 _blank 链接。如果有人知道那会很棒。

答案 1) - 没有用

我把它放在 WebViewDelegate.m -

UIWebViewNavigationType < 是错误

- (BOOL) webView:(WebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    //return [self.viewController webView:theWebView shouldStartLoadWithRequest:request navigationType: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"] || [[url scheme] isEqualToString:@"itms-apps"]) {
        [[UIApplication sharedApplication] openURL:url];
        return NO;
    }
    else {
        return [self.viewController webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
    }
}
4

2 回答 2

2

我认为 _blank 更改是最近的更改,尚未在 iOS 中实现。我目前使用这段本机代码AppDelegate.m在 Safari 中打开外部 URL

- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    //return [self.viewController webView:theWebView shouldStartLoadWithRequest:request navigationType: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"] || [[url scheme] isEqualToString:@"itms-apps"]) {
        [[UIApplication sharedApplication] openURL:url];
        return NO;
    }
    else {
        return [self.viewController webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
    }
}
于 2012-06-08T09:24:07.783 回答
0

适用于 2.3.0 oO'

- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType{
//return [self.viewController webView:theWebView shouldStartLoadWithRequest:request navigationType: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"] || [[url scheme] isEqualToString:@"itms-apps"]) {
    [[UIApplication sharedApplication] openURL:url];
    return NO;
}
else {
    return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
}}
于 2013-02-21T14:55:18.020 回答