cocoa – 禁用WebKit WebView

除了滚动之外,是否可以禁用与WebView的所有用户交互?我希望用户能够看到页面(并可能选择内容),但不能单击链接/右键单击/刷新/焦点表单字段/触发UI DOM事件(onclick等).

我在this question上看到我可以禁用右键单击和选择,但这对表单元素和导航发送DOM事件没有帮助.

解决方法

您可以继承NSWindow并将您的子类设置为WebView的窗口.然后,您可以通过检测鼠标事件影响的控件类型来控制将哪些事件发送到WebView.

这是非常强大的力量,但将完全禁用任何鼠标事件,包括翻转等:

@interface WebViewEventKillingWindow : NSWindow 
{
    IBOutlet WebView* myWebView;
}
@end

@implementation WebViewEventKillingWindow
- (void)sendEvent:(NSEvent*)event
{
    NSView* hitView;
    switch([event type])
    {
        case NSScrollWheel:
        case NSLeftMouseDown:
        case NSLeftMouseUp:
        case NSLeftMouseDragged:
        case NSMouseMoved:
        case NSRightMouseDown:
        case NSRightMouseUp:
        case NSRightMouseDragged:
            hitView = [myWebView hitTest:[event locationInWindow]];
            if([hitView isDescendantOf:myWebView] && 
                         !([hitView isKindOfClass:[NSScroller class]] || 
                             [hitView isKindOfClass:[NSScrollView class]]))
            {
                return;
            }
            break;
        default:
            break;
    }
    [super sendEvent:event];
}
@end

相关文章

我正在用TitaniumDeveloper编写一个应用程序,它允许我使用Ja...
我的问题是当我尝试从UIWebView中调用我的AngularJS应用程序...
我想获取在我的Mac上运行的所有前台应用程序的应用程序图标....
我是一名PHP开发人员,我使用MVC模式和面向对象的代码.我真的...
OSX中的SetTimer在Windows中是否有任何等效功能?我正在使用...
我不确定引擎盖下到底发生了什么,但这是我的设置,示例代码和...