Welcome to MSDN Blogs Sign in | Join | Help

Extending the Internet Explorer context menu

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.)

Published Monday, May 24, 2004 7:03 AM by oldnewthing
Filed under:

Comments

# re: Extending the Internet Explorer context menu

Monday, May 24, 2004 7:18 AM by Mulla Bill
You're fired! =)

# re: Extending the Internet Explorer context menu

Monday, May 24, 2004 7:37 AM by Chris Szurgot
This is great. Thanks! Now to figure out how to go the other way as well. :) ViewInIE (For Plugins that don't quite work)

# re: Extending the Internet Explorer context menu

Monday, May 24, 2004 7:52 AM by Ben Hutchings
Chris: See http://ieview.mozdev.org/ (this is for Firefox though).

# re: Extending the Internet Explorer context menu

Monday, May 24, 2004 8:04 AM by Josh Williams
http://www.rpi.edu/~willij3/hacks/IEContextMenu_Reg.txt

here's a couple of fun additions to the context menu that will take highlighted text and do one of the following:
- search Dictionary.com
- search google
- open in new window (for non linked URLs)
- search slashdot

I haven't used them for a while, so the URLs might have changed... But the funcationality is cool none the less.

# re: Extending the Internet Explorer context menu

Monday, May 24, 2004 10:15 AM by Clinton Pierce
I'm glad to see I'm not the only one who debugs these things in a series of alert() statements.

Do I have the object yet? Check. Revise. Does this property have what I want? Check. Revise. Okay now call the function that I wanted to call in the first place.

# re: Extending the Internet Explorer context menu

Monday, May 24, 2004 10:32 AM by Eric
Reg file:

----
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\View in Firefox]
"Contexts"=hex:20,00,00,00
@="C:\\Utilities\\ViewInFirefox.htm"

----
ViewInFirefox.htm:
----
<SCRIPT>
var shell = new ActiveXObject("WScript.Shell");
shell.run("firefox \"" + external.menuArguments.event.srcElement + "\"");
</SCRIPT>
----

This will do it for firefox; replace all occurrences of "firefox" with "mozilla" to do it for moz instead.

# re: Extending the Internet Explorer context menu

Monday, May 24, 2004 10:54 AM by Marc Wallace
This would have been a cleaner way for me to get 'view source' to dump into a real editor (with line numbers). I had to poke around the registry to figure out how to change the default behaviour; it never occurred to me that I could just add new behaviours. Very cool.

# re: Extending the Internet Explorer context menu

Monday, May 24, 2004 10:56 AM by Rob Eberhardt @ Slingshot Solutions
I find that IE's context menu fills up fast, and there seems to be no way to push extensions into a sub-menu.

However, there IS a mechanism for popping up a dialog with whatever GUI you want. That's what this tool takes advantage of:
http://slingfive.com/pages/code/ssPowerTools/. It's a ton of context menu extensions all rolled into one context menu item.

My favorite developer feature is the "Show Full Page Weight", which grabs and totals the byte-size of the HTML and all linked images/css/scripts/objects.

# external.menuArguments

Monday, May 24, 2004 11:28 AM by Marc Wallace
Is this only available if it's opening a file, rather than immediate mode? I try:

javascript:alert(external.menuArguments);

from the open dialog, and it returns undefined. Ditto if I include that in a MenuExt extension.

# re: Extending the Internet Explorer context menu

Monday, May 24, 2004 12:20 PM by Friend
Don't read Slashdot.

# re: Extending the Internet Explorer context menu

Monday, May 24, 2004 12:50 PM by David Candy
D. Shows how to change Tools - Show Related to use google instead of Alexa or MSN. C just seems somewhat relevent.

c/ Both Google Toolbar (http://toolbar.google.com/) and the IE5 Powertoys (http://www.microsoft.com/Windows/IE/WebAccess/ie5tools.asp ignore warnings on page) allow selecting a word in a web page then searching on it.

d/ If you want the Show Related Sites (Tools menu) to use Google rather than MSN or Alexa then
Type in Start Run
notepad %windir%\web\related.htm

Change the line

//RelatedServiceURL="http://related.msn.com/related.asp?url=";

to

RelatedServiceURL="http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=related:";

# "View in Mozilla" for Internet Explorer

Monday, May 24, 2004 5:59 PM by Lockergnome's Tech News Watch
Via Bink: "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."...

# re: Extending the Internet Explorer context menu

Monday, May 24, 2004 6:28 PM by Nauman Leghari
Some time ago, I wrote a little on this, and calling a .net component as the context menu action. See the article here
http://weblogs.asp.net/nleghari/articles/5319.aspx

# re: Extending the Internet Explorer context menu

Tuesday, May 25, 2004 1:32 AM by Rhys
Context menus are fantastic, I can't see why more isn't made of them. There are a few on my site and Microsoft has a collection here:
http://www.microsoft.com/windows/ie/previous/webaccess/webdevaccess.asp

Now if only firefox could implement something like that my life would be complete.

# re: Extending the Internet Explorer context menu

Tuesday, May 25, 2004 6:42 AM by Jim
Well its there in the full Mozilla suite and its been there for years.

Just go to Preferences - > Advanced -> DOM Inspector
And click the Install button.

Once installed it will appear in your Sidebar (hit F9 if you can't see the sidebar at the moment) or under the Tools menu in Web Developer -> DOM Inspector

And there is a plugin on mozdev.org that installs this for Firefox, but I cba to look for it.

# re: Extending the Internet Explorer context menu

Tuesday, May 25, 2004 6:44 AM by Jim
Forgot to mention that pretty much everything else in that download is in Firefox and enabled by default eg View Partial Source (aka View Selection Source) and searching for words on a page after highlighting them.

# re: Extending the Internet Explorer context menu

Tuesday, May 25, 2004 9:37 AM by Jan Söderback
Jim: Actually, the FireFox installer includes the DOM Inspector. Just choose the custom install.

# re: Extending the Internet Explorer context menu

Tuesday, May 25, 2004 10:37 AM by Michael Geary
"I'm glad to see I'm not the only one who debugs these things in a series of alert() statements.

Do I have the object yet? Check. Revise. Does this property have what I want? Check. Revise. Okay now call the function that I wanted to call in the first place."

I do this in practically all my code in any language. Instead of writing a whole pile of code and then trying to test it, I write the smallest amount of code that could do something leading toward my final goal. Once I see that it works, I add a little more and try it, and so on.

I'm much happier when I can go from working code to working code instead of dealing with a big heap of non-working code.

# re: Extending the Internet Explorer context menu

Tuesday, May 25, 2004 11:15 AM by David Candy
Michael Geary

Do other people do it differently. I've always been an individual programmer (one use custom programs in a language where variables are named after the line number they were created on). I'm compiling within a minute of my first character typed. I use msgbox even in the debugger. I ignore the debugger mostly though sometimes I use breakpoints.

# re: Extending the Internet Explorer context menu

Tuesday, May 25, 2004 12:47 PM by jb
On a somewhat related topic,it's also quite easy to extend the context menu of the Windows explorer. For instance, look up my Win32::ShellExt perl extension on CPAN, that allows you to write some in perl.
I'm sure it should be possible to put perl code in the SCRIPT tag to extend IE.

# re: Extending the Internet Explorer context menu

Tuesday, May 25, 2004 2:04 PM by T
You wouldn't believe how hard it is to explain debugging with alert(); or msgbox() to folks that didn't learn it that way.

Me? I started out on an Apple][+ and AppleBASIC where the primary method of output was the PRINT statement. I can't imagine not using some form of print/alert()/msgbox()/response.write for debugging, _especially_ web apps.

But I work with some folks that can have a bug pop up and ask me what's wrong. When I ask what the value of variable X is, they say "It's supposed to be...." To which I invariably reply, "Well, we know what it should be, but how do you know what it really is? Have you printed it out?" To which the reply is usually a blank stare. Well, it used to be. I've indoctrinated them. ;-)

Anyway, it _seems_ like the folks that learned to code with VB and have never used anything but VS tend to be less likely to be "alerters", while those that learned to code in a console environment tend to be avid "alerters".
That's just an off-the-cuff observation based on a few years dealing with various coders and would-be coders.

I could be wrong.

# re: Extending the Internet Explorer context menu

Tuesday, May 25, 2004 2:10 PM by Michael Geary
David: Believe it or not, I have run into people who write a huge mess of code and then start testing it, instead of taking little steps at a time. Um, I think I used to do that too, although I wouldn't admit it! :-)

I'm not a "unit test only, never use a debugger" type of guy, though. I like to use unit tests and a good debugger. Of course, for an example like Raymond's, you don't really have a debugger available, and the alert box is the way to go, using tiny steps with tests along the way.

# Extending the IE context menu

Friday, May 28, 2004 5:37 AM by edBlog

# re: Extending the Internet Explorer context menu

Wednesday, June 02, 2004 1:04 AM by Kevin
Thanks all! I'm using this to make an Urbandictionary.com search for myself!

# re: Extending the Internet Explorer context menu

Thursday, June 03, 2004 2:47 PM by Kevin
Ok so acutally it's not working. I get a javascript error with:

external.menuArguments.document.selection.createRange().text

and
@="javascript: alert(external.menuArguments.document);"

is null and:
@="javascript: alert(external.menuArguments);"

is undefined. Does anyone know a better way of capturing the highlighted text? (I'm using Win2k and WinXP and ie 6)

Thanks!
-Kevin

# re: Extending the Internet Explorer context menu

Thursday, June 03, 2004 2:52 PM by Raymond Chen
You don't put the script directly into the registry. The registry points to an HTML file, and you put the script into the HTML file.

# re: Extending the Internet Explorer context menu

Friday, June 04, 2004 2:32 PM by Kevin
Ok I got it to work as a separate file, but is it possible to launch right away? The fourth comment on this page (Josh Williams) claims you can, but I can't get his code to work either.

# re: Extending the Internet Explorer context menu

Friday, June 04, 2004 2:42 PM by Raymond Chen
You need to exit IE and restart it for it to pick up the new extensions (but you can edit an existing extension without needing to restart).

# re: Extending the Internet Explorer context menu

Friday, June 04, 2004 3:02 PM by Kevin
Ok I got it to work as a separate file, but is it possible to launch right away? The fourth comment on this page (Josh Williams) claims you can, but I can't get his code to work either.

# re: Extending the Internet Explorer context menu

Saturday, June 12, 2004 3:32 PM by Win Bent
@="javascript: alert(external.menuArguments);"

"You don't put the script directly into the registry. The registry points to an HTML file, and you put the script into the HTML file." (Raymond Chen)

It works on Win98 with the script in the registry, but fails on XP. Is there a way to put the script in the registry on XP? That would greatly simplify installation!

# re: Extending the Internet Explorer context menu

Saturday, June 12, 2004 3:36 PM by Raymond Chen
If there is I don't know how.

# re: Extending the Internet Explorer context menu

Monday, June 14, 2004 5:28 AM by Casual Programmer
Hi all,

thanks for exlaining about context menus.

I just implemented the context menu example with slight problems. As I run Norton Antivirus, it intercepts the "malicious" script, so you don't get to see wether it works unless you disable the "script blocking" feature. You can enable the "ask for action to be taken" option, but in my case it would not wait long enough to let me answer.

The URL given is MSDN explaining in depth which possibilities there are in configurating IE.

I now use

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

to start the DOM inspector from within IE, please be aware that this DOM is Mozilla DOM not MS ( i.e. "textContent" instead of "innerHTML" and the like.

Cheers, Casual

# re: Extending the Internet Explorer context menu

Monday, June 14, 2004 5:31 AM by Casual Programmer
P.S.

I am running XP SP2 / IE 6.0 / Mozilla 1.8a2

# re: Extending the Internet Explorer context menu

Wednesday, June 16, 2004 10:33 PM by Dumky
I used this technique as well, but with a little variation: you can host the script in a remote file. So all you need to do to install the menu is to install the registry key.

More details at:
http://blog.monstuff.com/archives/000033.html

# re: Extending the Internet Explorer context menu

Friday, June 18, 2004 1:36 AM by Mike
this doesnt work for me..:(

I inserted the code into the registry, created the .htm file and put it into the right place, but I still dont have a new entry in IE's context menu (= supposing, that context menu means, you right-click in the IE window on a web page and the menu that appears is the context menu...)

btw, I have a German XP Pro, but that shouldnt make the difference...

any ideas?

# re: Extending the Internet Explorer context menu

Friday, June 18, 2004 7:18 AM by Raymond Chen
Did you remember to launch a new copy of IE from the Start menu?

# re: Extending the Internet Explorer context menu

Friday, June 18, 2004 7:23 AM by Mike
yeah, I rebooted since then about 5 times...
still cant see anything..:(

# re: Extending the Internet Explorer context menu

Friday, June 18, 2004 7:40 AM by Raymond Chen
All I can think of is some subtle typo.

# re: Extending the Internet Explorer context menu

Friday, June 18, 2004 8:09 AM by Mike
well, I did the following:
put this in a file:
Windows Registry Editor Version 5.00

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

executed it, the value was inserted with a folder symbol into the registry, created the file c:\ViewInMozilla.htm with the following content:
<SCRIPT>
var shell = new ActiveXObject("WScript.Shell");
shell.run("mozilla \"" + external.menuArguments.document.URL + "\"");
</SCRIPT>

then rebooted...and nothing happened...double checked everything about 3 times...

# re: Extending the Internet Explorer context menu

Friday, June 18, 2004 8:16 AM by Raymond Chen
If you take a look at the registry you'll see that your .reg file didn't work. That's because what I gave above was not a .reg file; it was just a description of a registry key. I'm assuming people are thinking and not just blindly cutting/pasting.

# re: Extending the Internet Explorer context menu

Saturday, June 19, 2004 6:51 AM by bruce
can some possibly package this 'view in mozilla' thing into a simple reg file for normal humans to use? much like firefox simply lets you download an xpi?

# re: Extending the Internet Explorer context menu

Saturday, June 19, 2004 7:51 AM by Raymond Chen
Um, Eric already did in one of the comments.

Remember, my target audience is *not* normal users. It's advanced programmers.

# re: Extending the Internet Explorer context menu

Wednesday, June 30, 2004 7:24 AM by Raymond Chen
Commenting on this entry has been closed.

# FireFoxView Mozilla extension for IE

Saturday, December 11, 2004 11:52 AM by Darrell Norton's Blog
FireFoxView Mozilla extension for IE

# Browser peace and where (VS) 2005 can help.

Friday, December 31, 2004 11:21 AM by Peter's Gekko
Browser peace and where (VS) 2005 can help.

# IE: Kontextmen?eintrag - Winhistory Forum

Tuesday, June 19, 2007 3:28 PM by IE: Kontextmen?eintrag - Winhistory Forum
New Comments to this post are disabled
 
Page view tracker