我有一个web视图在我的Cocoa应用程序(MacOSX的不是iPhone),它会显示一些JavaScript的用户,但我不希望用户能够选择任何文字或单击鼠标右键,并选择重新加载选项。

有一种简单的方式来关闭与web视图的所有交互?

我知道在iPhone上它很容易禁用用户交互,但我从来没有需要之前做到这一点的桌面上并不能找到一个解决方案。

有帮助吗?

解决方案

设置两个编辑和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;
}

其他提示

经由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
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top