Cocoa webView - 禁用所有交互 [英] Cocoa webView - Disable all interaction

查看:132
本文介绍了Cocoa webView - 禁用所有交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a webView in my cocoa application (macosx not iphone), it displays some javascript to the user but I don't want the user to be able to select any of the text or right click and select the reload option.

有没有一个简单的方法来禁用与webView的所有交互?

Is there a simple way to disable all interaction with the webView?

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

I know on the iPhone its easy to disable user interaction but I have never needed to do this on the desktop before and can't find a solution.

推荐答案

编辑和UI委派:

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

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

Then add the methods above to disable text selection and context menu.

- (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;
}

这篇关于Cocoa webView - 禁用所有交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆