禁用WebKit WebView [英] Disable a WebKit WebView

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

问题描述

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

Is it possible to disable all user interaction with a WebView, apart from scrolling? I want the user to be able to see the page (and possibly select things), but not click links/right click/refresh/focus form fields/trigger UI DOM events (onclick etc).

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

I see on this question I can disable right click and selection, but that doesn't help with the form elements and navigation sending DOM events.

推荐答案

您可以子类化NSWindow并设置您的子类作为WebView的窗口。您可以通过检测哪种控件受鼠标事件影响,来控制哪些事件发送到WebView。

You could subclass NSWindow and set your subclass as the window of the WebView. You can then control which events are sent to the WebView by detecting what sort of control is being affected by the mouse event.

这是相当蛮力,但将完全禁用任何鼠标事件,包括rollovers等:

This is pretty brute force but will totally disable any mouse events, including rollovers etc:

@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

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

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