禁用 WebKit WebView [英] Disable a WebKit WebView

查看:21
本文介绍了禁用 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.

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

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天全站免登陆