启用单击webview中的链接

时间:2012-07-20 18:34:00

标签: objective-c macos

如何在mac osx webview中启用单击链接?

我有以下代码,但我不知道为策略委托实现哪些方法...

@synthesize myWebView = _myWebView;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification


    /* webview setup here, everything works fine 
    except cannot click links in webview..... */


    //setup my delegate
    _myWebView.policyDelegate = self;

}
//Now what?....

感谢。

1 个答案:

答案 0 :(得分:-2)

WebView对链接没有限制。

但是,如果在单击Web视图中的链接时需要自定义行为,则应在策略委托中实现“webView:decisionPolicyForNavigationAction:request:frame:decisionListener:”。然后,您可以从操作信息字典中获取操作类型,如果是链接点击事件,则可以执行自定义操作。

示例:

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

{

    NSUInteger actionType = [[actionInformation objectForKey:WebActionNavigationTypeKey] unsignedIntValue];
    if (actionType == WebNavigationTypeLinkClicked) {
        //Do your stuff
    } else {
        [listener use];
    }

}