Yellowpages Australia Bookmarklet
Building a better browser toolbar.
Drag the Yellowpages link to your toolbar to quicly search for any business in Australia.
The principle of a bookmarklet is almost always the same. Try and squeeze as much Javascript code into a Bookmark link as the browser will allow.
In the Yellowpages one , the bookmarklet shows a dialog, then appends the entered string to a yellowpages.com.au search query. Here is the code broken into bits so you can see how it works:
javascript:void(q=prompt(
‘Enter the name of a business to look up at Yellowpages.com.au’,
‘));
The first line tells the browser some javascript code is come. The second line, puts the value of ‘prompt’ into the q variable. The third is the text of our dialog box. The fourth would be where we could put some prewritten text inside the textbox if we wanted, but in this case it is empty, so its just ‘’. The two brackets close the prompt command, and the ‘;’ sends it.
if(q)void(location.href=’http://yellowpages.com.au/search/performSearch.do?
location=9 &serviceArea=true&saveSearch=true&x=42&y=10
&businessName=’+escape(q))
In the second command of our bookmarklet we begin with an if statement. The second line contains the basic url that Yellowpages uses to do a search. On the third line we buildin some default settings, such as searching all of Australia (Option 9 on the Yellowpages search page is ALL STATES), saveSearch=true causes the site to remember your search for the future. I don’t know what x=42 or y=10 does, maybe it is somesort of tracking code? Line 4 appends the the text we typed in earlier and attaches it to the businessName parameter. Because Javascript is testing the IF question (to work out if it is true or not), the bookmarklet tells the browser to go to Yellowpages website. The question being tested is:
if www.yellowpages.com + businessname + the value of variable q
Javascript will never find out the answer to that IF question because our browser has wisked us away to run a search on the Yellowpages website, and the result is a listing of all the businesses matching the text we typed in.
This principle can be applied to may sites that have a search feature, and can often save us from having to seek out the search page on a website first.
More great bookmarklets
There are even better examples at Jesses’s Bookmarklet Site, which is split into 16 catagories such as Links, Forms, Text/Data, Zappers, Wed Dev, Validation, Search Engines and more