问题
I have a WebView in a window. In the WebView, I am able to restrict it to load its default contextual menu. I need to add a custom contextual menu for the WebView. So, please post a sample regarding this. I am new to Mac development. Please help me in this issue.
Thanks in advance.
回答1:
Assign an object as the web view's WebUIDelegate and implement this delegate method:
- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element defaultMenuItems:(NSArray *)defaultMenuItems
You can then return an array of menu items that you want in the contextual menu. You can either add them to the defaultMenuItems array or return a new array containing only your items.
来源:https://stackoverflow.com/questions/6585075/webview-load-custom-context-menu