JavaScript Tips & Tricks #3: Bookmarklets

A bookmarklet is a tiny JavaScript program contained in a bookmark which can be saved and used the same way you use normal bookmarks. A bookmarklet is simpler than a traditional program--there is a limited amount of room in a bookmark; usually they are only two or three lines of code of less than 256 characters. Bookmarklets allow you to directly access search engines, customize navigation, modify the way you see a page, extract data, control cookies, turn off images, etc.

This changes the background color of a web page to white. Useful if you can't distinguish the text from the background.

Page Color to White

The void operator discards the value of its operand and returns an undefined value. It is often used with the javascript: URL to ignore the results of expressions. This bookmarklet opens a new window containing a copy of whichever page you are viewing. This allows you to surf away from the page and still quickly return to the copy (you don't have to reload it).

Open Copy...

This bookmarklet lists the screen width and height and number of colors available:

Screen Properties

Resize the window to 640 x 480 pixels (so you can check what a page looks like at a smaller resolution):

Resize (640 x 480)

To keep a bookmarklet, so you can use it on other pages later: In Internet Explorer, point at the bookmarklet link, click the right mouse button and choose "Add to Favorites". You can also drag the link up to your Favorites menu. To use the saved bookmarklet in Internet Explorer, simply click on it in your Favorites panel.

In Netscape Navigator, point at bookmarklet link, click the right mouse button and choose "Add Bookmark". You can also drag the bookmarklet to your Bookmarks menu; when the menu opens, drag to whichever place you prefer.

This bookmarklet takes you to the robots.txt file for the site you are visiting. The robots.txt file is used to indicate parts of a site that should not be crawled by search engines. It may or may not show you a "hidden" part of the site, or other interesting information. Not all sites have robots.txt files.

Show Robots.txt

Encode and decode strings using the HTTP URL encoding scheme:



You can design bookmarklets that do general or very specific searches on just about any search engine.

Prompt for and search for a word in the UCSD Webster dictionary server:

Search Webster

If you are using a 56K modem to connect to the Internet, this will provide quick estimates of how long it will take to download a file of known size:

Download Time...

Normally when you point at a link you can see the destination URL in the status bar at the bottom of your browser window. This can be useful when deciding whether or not to click on a link, but some sites use JavaScript to put other messages there instead. This bookmarklet restores the default behavior; when you point at a link you'll see the URL.

Show Destinations

You can more about bookmarklets at or by searching on 'bookmarklets'