Adding to the Standard Context MenusItems can be added to the existing context menus of the WebBrowser control by placing entries in the registry and linking these to URLs that execute script. To add additional items to the standard WebBrowser context menus, create or open the following key:
The following registry entry will add an item with the title "My Menu Item" to the WebBrowser context menu and will execute the inline script contained in the file "c:\myscript.htm."
My Menu Item = "file://c:\myscript.htm"
var parentwin = external.menuArguments;
var doc = parentwin.document;
var sel = doc.selection;
var rng = sel.createRange();
var str = new String(rng.text);
if(str.length == 0)
rng.text = "MY INSERTED TEXT";
rng.text = str.toUpperCase();
Optional KeysUnder the item registry key created earlier, there are a couple of optional values. One of these specifies on which context menus this item will appear. The other specifies that the script should be run as a dialog box.
The "Contexts" DWORD value specifies the context menus in which an item will appear. It is a bit mask consisting of the logical OR of the following values (defined in mshtmhst.h). These values correspond to the constant passed in a IDocHostUIHandler::ShowContextMenu call.
(0x1 << CONTEXT_MENU_DEFAULT) (evaluates to 0x1)
(0x1 << CONTEXT_MENU_IMAGE) (evaluates to 0x2)
(0x1 << CONTEXT_MENU_CONTROL) (evaluates to 0x4)
(0x1 << CONTEXT_MENU_TABLE) (evaluates to 0x8)
(0x1 << CONTEXT_MENU_TEXTSELECT) (evaluates to 0x10)
(0x1 << CONTEXT_MENU_ANCHOR) (evaluates to 0x20)
(0x1 << CONTEXT_MENU_UNKNOWN) (evaluates to 0x40)
(0x1 << CONTEXT_MENU_DEFAULT) | (0x1 << CONTEXT_MENU_TEXTSELECT)
The Context Menu EventWhenever a context menu extension is triggered, the event object off of the main window (external.menuArguments.event) contains information about where the user clicked and which context menu was shown. The mouse coordinates are valid along with event.srcElement. The event.type value contains one of the following strings, indicating which context menu was shown to the user:
Another ExampleThis example will create a new context menu item on just the default menu. This item, called "Show in New Window" will start whatever is clicked on in a new window. So, If something is deeply nested in a frameset, you can easily launch a specific frame in its own window. Here are the contents of a .reg file that can be run to insert the correct registry settings. Call this Example2.reg. Double-clicking on this file in the Explorer will insert the settings in your registry. REGEDIT4
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Show in
ID d'article : 177241 - Dernière mise à jour : 22 juin 2014 - Révision : 1