【问题标题】:Cocoa: how to disable all the user interactions of a web view in cocoa?Cocoa:如何禁用可可中 Web 视图的所有用户交互?
【发布时间】:2012-06-08 03:55:04
【问题描述】:

假设我有一个 Webview 超过另一个,并且我正在内部 Web 视图中加载一个页面。 现在我想禁用外部 Webview 的所有用户交互。 如何在桌面编程中实现这一点?

这里是代码段:

IBOutlet WebView *innerWebView;
IBOutlet WebView *outerWebView;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
   // NSString *path = [[NSBundle mainBundle] pathForResource:@"main" ofType:@"html"];
   // NSURL *url = [NSURL fileURLWithPath:path];
    [[myWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://icicibank.com"]]];
    [outerWebView setDrawsBackground:NO];
    [outerWebView setEditable:NO];

}
- (void)webView:(WebView *)webView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id < WebPolicyDecisionListener >)listener{
    [myWebView setDrawsBackground:NO];
    [myWebView setEditable:NO];
    [outerWebView setDrawsBackground:YES];
    [outerWebView setEditable:YES];
    NSLog(@"hello");
    [[outerWebView mainFrame] loadRequest:request];
    [outerWebView webViewShow:outerWebView];
}

这些是网点。

【问题讨论】:

  • 什么是“一个 web 视图优于另一个”? Webview 的-setEditable: 有效吗?

标签: objective-c cocoa webview


【解决方案1】:

检查此问题的已接受答案:

Cocoa webView - Disable all interaction

答案谈到了几个用户事件。您可以从WebUIDelegate 协议和WebEditingDelegate 协议中选择适合您需要的方法。

【讨论】:

    【解决方案2】:

    将 BODY 中的所有 html 代码放在 &lt;div onmousedown="return false"&gt; ... &lt;/div&gt; 之间。例如,这将帮助您避免用户拖动图像...

    也添加这个方法:

    //Disabling the right click menu 
    - (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element defaultMenuItems:(NSArray *)defaultMenuItems {
        return nil;
    }
    

    【讨论】:

      猜你喜欢
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-13
      • 2023-03-07
      • 1970-01-01
      • 2012-07-29
      相关资源
      最近更新 更多