Googling from Internet Explorer

This is a re-post but I find this so useful that I’m sure it’s worth reposting.

 

I’m always wanting to pick up an arbitrary piece of text in Internet Explorer and launch a Google search for it without having to type it in to a new Window.

 

What I use to do this is as follows…

 

You need to create a registry key;

 

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\My &Google Menu Name

 

Then under there you need to set a default value which needs to be something like;

 

file://c:\myfolder\myscript.htm

 

And you also want to make a new DWORD value called Contexts which you set to 16 (0x10).

 

And then in your HTM script file you need something like (i.e. it’s not perfect);

 

var parentwin = external.menuArguments;

var doc = parentwin.document;

var sel = doc.selection;

var rng = sel.createRange();

var str = new String(rng.text);

var googleUrl = ‘http://www.google.com/search?q=’;

if(str.length != 0)

{

var i;

var words = str.split(‘ ‘);

for (i = 0; i

{

if (i)

{

googleUrl += ‘+’;

}

googleUrl += words[i];

}

}

parentwin.navigate(googleUrl);

 

 

And you can replace the parentwin with window if you want a new window rather than navigating the current one. This seems to work ok for me – I’m sure it’s already out there but just in case it’s not…

 

If you’re struggling with it then here is the exported MenuExt registry key from my PC and here and here are the two HTML pages they refer to – you’d just need to change the file paths to reflect where you put the HTM files on your PC.