假设我有一个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];
}
这些是出口。
答案 0 :(得分:1)
检查此问题的已接受答案:
Cocoa webView - Disable all interaction
答案谈到了几个用户事件。您可以从WebUIDelegate
协议和WebEditingDelegate
协议中选择适合您需要的方法。
答案 1 :(得分:0)
将来自BODY的所有html代码放在<div onmousedown="return false"> ... </div>
之间。这将帮助您避免用户拖动图像...
也添加此方法:
//Disabling the right click menu
- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element defaultMenuItems:(NSArray *)defaultMenuItems {
return nil;
}