Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa webView - Disable all interaction

Tags:

cocoa

webview

I have a webView in my cocoa application (macosx not iphone), it displays some javascript to the user but I don't want the user to be able to select any of the text or right click and select the reload option.

Is there a simple way to disable all interaction with the webView?

I know on the iPhone its easy to disable user interaction but I have never needed to do this on the desktop before and can't find a solution.

like image 386
Craig Avatar asked Aug 09 '09 15:08

Craig


1 Answers

Set both editing and UI delegations:

[view setUIDelegate:self];
[view setEditingDelegate:self];

Then add the methods above to disable text selection and context menu.

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

- (BOOL)webView:(WebView *)webView shouldChangeSelectedDOMRange:(DOMRange *)currentRange 
    toDOMRange:(DOMRange *)proposedRange 
    affinity:(NSSelectionAffinity)selectionAffinity 
    stillSelecting:(BOOL)flag
{
    // disable text selection
    return NO;
}
like image 135
Nando Vieira Avatar answered Sep 28 '22 19:09

Nando Vieira