Customize the Firefox Quick Search Box

Though Yahoo! Web Search is a default option in the Firefox search box, with some quick coding you can add many other Yahoo! Search types.

If you use the Firefox web browser (available at http://www.mozilla.org/products/firefox), you’re probably already aware of the useful search box in the upper-right corner. From any page, at any time, you can simply type a query into the box and press Enter to bring the search page up in the browser. Though Google is the default search engine, you can click the arrow to choose another search engine, as shown in Figure 1-43.

Firefox search box options

Figure 1-43. Firefox search box options

Yahoo! Web Search is a default option, and once you choose Yahoo! from the drop-down list, it will stay your top choice until you change it again.

The nice thing about this list of potential search engines is that you can add any search engine of your choice. In fact, Firefox offers an Add Engines…option that takes you to a page with more search choices you can install with a few clicks. The New Search Engines section contains a page (http://mycroft.mozdev.org/quick/yahoo.html) full of over 30 different Yahoo!-related searches you can add to the Firefox search box. These are searches that others have found useful and decided to share with the larger Mozilla community (Mozilla is the technology behind Firefox). The specialty Yahoo! searches include everything from searching Yahoo! Auctions and searching Yahoo! in different countries, to the Yahoo! Oxford Shakespeare reference. If you find yourself constantly looking for pithy quotes from The Tempest, adding this option to the Firefox search box could be the stuff dreams are made of.

To add a search engine from this Mozilla page, simply click the name of the search engine you’d like to add. A pop-up box will ask you to confirm your choice; click OK, and the new choice will be available in the Firefox search box menu. Behind the scenes, Firefox has copied a small .src file and icon to the searchplugins directory of the Firefox installation. This text file defines how the search works.

If you don’t find the search of your dreams at the Mozilla page, it’s fairly easy to build your own specialty Yahoo! search and add it to your list of available search engines. You just need a simple text editor to create the search engine text file, and an eye for spotting patterns in search URLs.

The Code

Maybe you’re a fan of the Yahoo! Image Search (http://images.yahoo.com) and you’d like to be able to search for images quickly from Firefox. The first step in creating a custom entry is to perform a search and take a look at the URL. For this example, browse to http://images.yahoo.com, type Shakespeare into the search form, and click Search Images. You should receive a page full of various pictures of Shakespeare, but take a look at the URL in the address bar. The relevant pieces of the URL include the images.search.yahoo.com domain, the images file, and the p variable, which is set to the search query:

	http://images.search.yahoo.com/search/images?p=shakespeare

Now that you know how Yahoo! Image Search URLs are constructed, you can write the file that will tell Firefox where to send search requests. Create a file called yahoo_image.src in a plain-text editor such as Notepad, and add the following code:

	# Yahoo! Image Search
	#
	# Created April 16, 2005

	<SEARCH
		version="7.1"
		name="Yahoo! Image Search"
		description="Search for images at Yahoo!"
		method="GET"
		action="http://images.search.yahoo.com/search/images" >

	<input name="p" user>

	</search>

As you can see, this quick file begins with an opening <SEARCH> tag that holds the name of the search, and a brief description. Everything before the question mark in the search results URL becomes the value of the action attribute. The input tag lets Firefox know the value should come from user input and that it should be named p, as in the Yahoo! Image URL.

Running the Hack

Save the file and add it to the Firefox searchplugins directory, usually located at C:\Program Files\Mozilla Firefox\searchplugins on Windows and at /Applications/Mozilla.app/Contents/MacOS/searchplugins on Mac OS X. You’ll also need an icon for the search, and because Firefox comes with a Yahoo! search option, you can simply copy the existing yahoo.gif file from the searchplugins directory and name it with the same prefix as your new Yahoo! Image Search text file—yahoo_image.gif, in this example.

Once you restart Firefox, you’ll find a new option in the search list called Yahoo! Image Search. Choose this option and type the original Shakespeare query in the search box. If all goes well, you should see a page of Shakespeare images like the one shown in Figure 1-44.

Yahoo! Image Search results via the Firefox search box

Figure 1-44. Yahoo! Image Search results via the Firefox search box

If you find yourself using a particular Yahoo! search time and again, you might be able to speed up your access to the search with an eye for search URLs and some quick text editing.

Get Yahoo! Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.