Disable Right Click Menu in WebView

Is there any way to disable the right click menu in a WebView Window? A program I’m working on uses a WebView and the contrents of the right click menu would be nice to control, if not disable. Thanks for any insight into this.

You need to do this with obj-c.

First, create a subclass of WebView. To do this, click on the ‘classes’ tab in IB main nib window, then click on your web view. The class “WebView” should be highlighted in the nib window. With WebView selected, choose “Subclass WebView” from the “Classes” menu in the main menu bar. A new subclass of webview will be created and will probably be named “MYWebView” by default. Rename this with a name representative of your project, for example if your project is named “ZipZap.app”, then call this something like “ZZWebView”. Next, make sure your new subclass is selected, and choose “Create files for ZZWebView” in the “Classes” main menu. You will be prompted to confirm that you want to create ‘ZZWebView.h’ and ‘ZZWebView.m’… which you do. Then, with your web view selected in IB, go to the “Custom Class” pane in the inspector window (cmd-5). Change the class of your web view from the default WebView to your new ZZWebView subclass, which you should now see in the list.

Next, go to Xcode and locate the new ‘ZZWebView.h’ and ‘ZZWebView.m’ files. They may be under resources, or in your classes group if you already have one. Place the following code into your two obj-c files…

This will set the uidelegate of the web view to itself and always override the contextual menu with a list of nil objects. Seems to work in one of my projects, should work for you.


Thank you so much for your effort Mr. Jobu, it works like a charm. This C code you have put forth really is amazing, and I really hope someday I’ll be able to return the favor. Thanks!