O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  


 
Buy the book!
Amazon Hacks
By Paul Bausch
August 2003
More Info

HACK
#11
Search Amazon from Any Web Page in IE
Searching Amazon from any web page can be as simple as highlighting and clicking with an Internet Explorer context menu
The Code
[Discuss (4) | Link to this hack]

The Code

First, the JavaScript. This bit of code will open a new browser window and plug the highlighted text into a URL. This code needs to be in a file somewhere on your computer where it can be accessed from the browser, and won't be deleted in a fit of spring cleaning. You could even create a new folder for it, c:\scripts\. If you have another location in mind, be sure to change any references to c:\scripts\ in the following code.

Create a file called AmazonSearch.html and add this code:

<script language="JavaScript">
var searchURL = new String("http://www.amazon.com/exec/obidos/[RETURN]
external-search/mode=blended&keyword=");

var w = window.external.menuArguments;
var d = w.document;
var s = d.selection;
var r = s.createRange(  );
var term = new String(r.text);

window.open(searchURL + term);
</script>

Save it in the c:\scripts\ directory.

Next you need to add some information to your Windows registry to let Internet Explorer know where to find AmazonSearch.html, and when exactly it should be executed. You could open up a registry editor and add values manually, but it's just as easy to put the information into a .reg file and add it by double-clicking. Create a new file called AmazonContext.reg and add the following code:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\[RETURN]
Search Amazon]

@="c:\\scripts\\AmazonSearch.html"
"contexts"=dword:00000010

TIP

Backslashes, like those in filesystem paths, need to be escaped as double-slashes (\\) in registry entry files.

Save the file on your desktop, double-click it, and confirm that you want to add the new registry information. This setting adds a right-click menu entry called "Search Amazon" that will appear whenever text is highlighted. It also points to the JavaScript file and will execute it when the highlighted entry is clicked.


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.