2012-06-08 54 views
3

我正在使用以下https://github.com/apache/incubator-cordova-mac來製作mac os x應用程序,但看起來我無法獲取_blank鏈接來打開。如果有人知道那會怎麼樣。cordova mac在safari中打開網址

答案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]; 
    } 
} 

回答

2

我覺得_blank變化是最近的一個還沒有在iOS中實現。我目前使用的這片原生代碼中AppDelegate.m在Safari

- (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]; 
    } 
} 
+0

我得到一個錯誤,當我把我的代碼,我將在 – RussellHarrower

+0

以上編輯嗯,我在Cordova應用程序中使用此功能,而不是在Cordova Mac組件中使用此功能。您可能需要調整代碼以在組件中使用,而不是在應用程序中使用。只要尋找等效的方法。 – codemonkey

+0

任何人都用phonegap 2.x試過這個嗎? – sonjz

0

打開外部URL這個製作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 ]; 
}}