Cocoa webView - 禁用所有交互

时间:2009-08-09 15:16:59

标签: cocoa webview

我的cocoa应用程序中有一个webView(macosx而不是iphone),它向用户显示一些javascript,但我不希望用户能够选择任何文本或右键单击并选择重新加载选项。

是否有一种简单的方法可以禁用与webView的所有交互?

我知道在iPhone上很容易禁用用户交互,但我以前从未需要在桌面上执行此操作,但无法找到解决方案。

2 个答案:

答案 0 :(得分:39)

设置编辑和UI委派:

[view setUIDelegate:self];
[view setEditingDelegate:self];

然后添加上述方法以禁用文本选择和上下文菜单。

- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element 
    defaultMenuItems:(NSArray *)defaultMenuItems
{
    // disable right-click context menu
    return nil;
}

- (BOOL)webView:(WebView *)webView shouldChangeSelectedDOMRange:(DOMRange *)currentRange 
    toDOMRange:(DOMRange *)proposedRange 
    affinity:(NSSelectionAffinity)selectionAffinity 
    stillSelecting:(BOOL)flag
{
    // disable text selection
    return NO;
}

答案 1 :(得分:3)

通过UI委派,禁用拖放操作也可能很有用,添加

- (NSUInteger)webView:(WebView *)sender dragSourceActionMaskForPoint:(NSPoint)point
{
    return WebDragSourceActionNone; // Disable any WebView content drag
}

- (NSUInteger)webView:(WebView *)sender dragDestinationActionMaskForDraggingInfo:(id <NSDraggingInfo>)draggingInfo
{
    return WebDragDestinationActionNone; // Disable any WebView content drop
}
相关问题