2012-04-26 43 views

回答

4

實際上,您可以在默認瀏覽器中加載您單擊的鏈接。

對於您必須實現WebPolicyDecisionListener協議並設置policyDelegateWebView

[webView setPolicyDelegate:self]; 

,然後實現以下方法:

-(void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener 
    { 

     if (WebNavigationTypeLinkClicked == [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue]) 
     { 
      [listener ignore]; 
      NSLog(@"Opening URL in browser:%@",[request URL]); 
      [[NSWorkspace sharedWorkspace] openURL:[request URL]]; 

     }  
     [listener use]; 
    } 

-(void)webView:(WebView *)webView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id <WebPolicyDecisionListener>)listener 
    { 
     if (WebNavigationTypeLinkClicked == [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue]) 
     { 
      [listener ignore]; 
      NSLog(@"Opening URL new window:%@",[request URL]); 
      [[NSWorkspace sharedWorkspace] openURL:[request URL]]; 
     } 
     [listener ignore]; 
    } 

此鏈接,你點擊會在[請求URL]

收到此代表方法
+1

這個迴應應該被接受。我測試過它並且工作得很好。 – omarrr 2014-07-11 20:21:33

相關問題