You can add custom menu item to IE standard context menu to do some custom actions. For example you may want to add an item to open an executable program and do something based on selected text.
As an option to add custom menu item to IE context menu, you can follow these steps:
- Open registry and go to:
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt
- Create a new key, and set the name of key to the text you want displayed in the context menu as the name, for example:
Open My App
-
Right click on
(Default)
and chooseModify...
and set the value to path of an html file which will contains some scripts to do a custom operation for you. For example:C:\OpenMyApp.html
-
Add a new
DWORD
value namedContext
and set it’s value to hexadecimal11
or decimal17
. This way, the context menu will be shown when you select a text or by default, but no when you right click on a button for example. To see more options take a look at documentation. Also in documentations it’s said to add binary but I triedDWORD
instead and it worked. Also other extensions that I’ve seen useDWORD
. Here is the list of available values based on the documentation:Context Value Default 0x1 Images 0x2 Controls 0x4 Tables 0x8 Text selection 0x10 Anchor 0x20 - Use this content for your
C:\OpenMyApp.html
:<script type="text/javascript"> var win = window.external.menuArguments; var selection = win.getSelection(); alert(selection); </script>
Now if you select a text and right-click on the text, you will see Open My App in context menu:
If you want to open an application, it’s enough to add some script to open the application for you. Your application should be installed on client and if you are going to use the selected text in your application, then your application should handle command line arguments by accepting string[] args
as input parameters for Main entry point or using Environment.GetCommandLineArgs()
.
The script to open an application should be like this:
<script type="text/javascript">
var win = window.external.menuArguments;
var selection = win.getSelection();
var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\\MyApp.exe";
oShell.ShellExecute(commandtoRun,"\"" + selection + "\"","","open","1");
</script>
Awesome post, I’ve been for something like this , , , , forever, lol
Do you happen to know if there’s a way to create submenu/cascades, like this ? can’t seem to find anything searching.
Thanks in advance