2012-10-21 80 views
0

通常,當你點擊網頁瀏覽器上的「使用Facebook註冊」按鈕時,會彈出一個新選項卡。但是,當您嘗試在WebView上執行同樣的操作時,它不會執行任何操作,而是停留在同一網站上。我如何強制WebView顯示對話框?如何強制WebView顯示FB授權對話框?可可

回答

0

這是你可能尋找。把它放在你的AppDelegate.m裏面,那麼所有的外部鏈接將在默認瀏覽器中打開:

// Habilita links externos abrirem no navegador padrão 
- (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request 
{ 
    // HACK: This is all a hack to get around a bug/misfeature in Tiger's WebKit 
    // (should be fixed in Leopard). On Javascript window.open, Tiger sends a null 
    // request here, then sends a loadRequest: to the new WebView, which will 
    // include a decidePolicyForNavigation (which is where we'll open our 
    // external window). In Leopard, we should be getting the request here from 
    // the start, and we should just be able to create a new window. 

    WebView *newWebView = [[WebView alloc] init]; 
    //[newWebView setUIDelegate:self]; 
    [newWebView setPolicyDelegate:self]; 

    return newWebView; 
} 

- (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener { 
    if([sender isEqual:myWebView]) { 
     [listener use]; 
    } 
    else { 
     [[NSWorkspace sharedWorkspace] openURL:[actionInformation objectForKey:WebActionOriginalURLKey]]; 
     [listener ignore]; 
     //[sender release]; 
    } 
} 

- (void)webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id<WebPolicyDecisionListener>)listener { 
    [[NSWorkspace sharedWorkspace] openURL:[actionInformation objectForKey:WebActionOriginalURLKey]]; 
    [listener ignore]; 
} 
// - 

(SIM,歐盟SOU BR!)

相關問題