Hi,
Yes. Your solution would work. There are three different context menus involved:
1. The WebControl's ContextMenu. This menu is the ContextMenu control that you associated to the WebControl in your host application. For example, for Windows Form application, this would be a ContextMenu/ContextMenuStrip that you associate to the control in the Form designer. If this context menu is set, then the context menu for step 2 is ignored;
2. The WebView's context menu. This is the default context menu provided by the browser engine. It has a few standard context menu items such as Back, Forward, Print, etc. This context menu can be overridden through BeforeContextMenu event;
3. The web page's context menu. This is the JavaScript code that responds to mouse right click and display some UI elements. This is no different than JavaScript code that responds a button clicks and invokes alert to display a message box. One way to avoid this is to modify the page's code in order to modify its behavior, this is essentially what you are doing.
The other way to do this is to "eat" the right mouse button up message. This will prevent all context menus. The code would be something like this:
Code: C#
private class MsgFilter : EO.WebBrowser.IInputMsgFilter
{
InputMsgTarget IInputMsgFilter.PreDispatchMsg(int Msg, IntPtr wParam, IntPtr lParam)
{
//0x204 = WM_RBUTTONDOWN
//0x205 = WM_RBUTTONUP
if ((Msg == 0x0204) || (Msg == 0x205))
return InputMsgTarget.None;
return InputMsgTarget.Application;
}
}
webView.InputMsgFilter = new MsgFilter();
This will short circuit both right mouse button down and right mouse button up message thus would prevent all context menus. Since it would prevent all context menus, your solution might work better for your case since when you do it with JavaScript, it only prevent context menu #3.
Hope this helps.
Thanks!