Extending the Internet Explorer context menu

Raymond Chen

Raymond


In a comment
,

Darrell Norton
asked
for a “View in Mozilla” option for Internet Explorer.

You can already do this.

Internet Explorer’s

context menu extension mechanism

has been in MSDN for years.
Let me show you how you can create this extension yourself.

First, create the following registry key:

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\View in Mozilla]
@=REG_SZ:"C:\some\path\to\ViewInMozilla.htm"
Contexts=REG_DWORD:1

Of course, you need to change C:\some\path\to to an actual path.

How did I know to do this?
Because steps 1, 2 and 3 in the “Implementation Steps” section tell
me (1) what key to create, (2) what to set the default value to, and
(3) what to set Contexts to.
I chose a Context value of 1, which means “Default”.

Okay, now to write the script ViewInMozilla.htm.
Well, the documentation says that I can access context
from the

menuArguments

property of the

external
object.
So let’s start with that.

<SCRIPT>
alert(external.menuArguments);
</SCRIPT>

Okay, let’s run this puppy. Launch IE, right-click on a blank
space in the web page, select “View in Mozilla”, and you get…

    [object]

Woo-hoo! This is a major accomplishment: Something happened at all.
Doing things in small steps makes it easy to identify where a problem is.
If we had run full steam ahead to completion
and then it didn’t work, we wouldn’t have
known whether it was due to a bug in the script, a bad registration, a bad
filename…

Now that I have the menu arguments, I can use that
to suck out information about the item that the context menu
applies to. Let’s try this:

<SCRIPT>
alert(external.menuArguments.document.URL);
</SCRIPT>

Woo-hoo, now it gives me the URL. Almost there. All that’s
left to do is to run a program with that URL as the command line
parameter.

<SCRIPT>
var shell = new ActiveXObject("WScript.Shell");
shell.run("mozilla \"" + external.menuArguments.document.URL + "\"");
</SCRIPT>

Mission accomplished.

Now you too can create Internet Explorer context menu extensions.

In fact, go ahead and do it, since Darrell asked for it:
Create an Internet Explorer
context menu extension that operates on anchors and opens the
linked-to page in Mozilla.

(Bonus:

Tony Schreiner

cooked up

something similar for zooming
.)

Raymond Chen
Raymond Chen

Follow Raymond