Page 1 of 1

Bookmarklets − Did you know of them Rate Topic: -----

#1 bhandari   User is offline

  • D.I.C Addict
  • member icon

Reputation: 9
  • View blog
  • Posts: 754
  • Joined: 31-January 08

Post icon  Posted 08 February 2008 - 12:23 AM

Hi All,

Lets learn the what of Bookmarklets here. So here we go.......

1. Introduction

Web browsers provide a visual clue to the user about hyperlinks in
the document [being viewed] by changing the mouse-pointer to the
icon of a hand with a pointing index finger as in Internet Explorer.
A subsequent mouse click loads the web page contained in the
What if the user wanted just the clue to the URL, and did not want to be transported to a new web page?

This would be tantamount to instructing the browser to provide
visual indication, but not to respond to the mouse click event. It
raises the question that is central to the behavior discussed:

"If the need is to suppress the action alone, why should <A> (the anchor) tag be used"

2. Investigating <A> the Anchor tag

The most common way of programming hyperlinks in HTML is
done by using the <A> (anchor) tag.
Working with this tag for a while, one figures out that there are
essentially two tasks tied to the anchor tag

• Visual indication on mouse rollover
• Taking action on mouse click

In its most commonly encountered usage, the anchor tag is made to
take the default action − page navigation. However, by selecting an
action that deviates from the default, the anchor tag can provide
interesting alternatives. For instance, one could make use of this
functionality to accomplish the following:

• Provide no more than a visual indication of hyperlinks in a
• Carry out some processing in response to a mouse click instead
of loading another page
• Suppress the display of the URL that is being navigated to in
the status bar

Here, it is important to note that the approach of invoking
Javascript via the address bar, on the document being displayed by
the browser, makes a very important assumption – that the browser
is Javascript enabled!
To illustrate, let us consider the following example, of a code
snippet containing a simple a hyperlink, which on selection, navigates
to another web page:

<a href=""></a>

Instead of the standard URL (which is an instruction to the browser
to navigate to a certain specified page) we could have the href
specifying that the response instead be an alert. This is encoded as
follows within the href tag.

<a href="java script:void(0)" onclick="alert('You clicked on')"></a>

A mouse click, instead of transporting the user to the Microsoft
site, will now pop the message:

"You clicked on"

The java script:void(0) function basically deactivates the hyperlink
to allow the developer to carry out some DHTML activity within
the onclick event.
One can also accomplish the same behavior adding a "return false;"
at the end of the onclick event code, but would still have to provide
an input for the href property. This, it could be more elegant
to make use of java script:void(0), here.
The story of void() does not end here. Although java script:void(0)
is the most widely used form of the void() function, one can have it
invoke a Javascript function as given below:

<a href="java script:void(alert('You clicked on'))"></a>

3. Bookmarklets

If you are wondering about it now, it is time to introduce formally,
the Bookmarklet. Bookmarklets are small Javascript programs that
can be run on the URL bar of the browser.
Steve Kangas of coined the term "Bookmarklet,"
which he created based on an idea suggested in the Netscape
Javascript Guide.
It is a common practice to use the Bookmarklet as a bookmark in
the browser (like a bookmark to an URL). This makes Bookmarklet
to be available as a single click option when needed. So the
term Bookmarklet is treated as a Bookmark + applet. Note that
Bookmarklets are not applets. Bookmarklets are sometimes also
referred to as Favelets.

4. What do Bookmarklets offer me?

This question can be answered easily depending upon your usage
of the browser.
• If you are a web developer and writing HTML related code,
then, Bookmarklet offers you a lot of utilities for developments.
Using Bookmarklet, it is possible to access the complete
DOM structure of the currently loaded in the browser.
This offers a lot of possibilities. For example, viewing the
nesting of the frames/table/div. Accessing/updating the properties
of each of the DOM elements etc…
• If you are a normal user then, then Bookmarklet offers you
lots of utilities that could enhance your browsing experience.
Using Bookmarklets, you can customize the way you want to
view the page, change the font size, color of the page to suite
your comfort, highlight a search words on a page, retrieve a
section as an html page, automatically enter your password

4.1. Hello World! Bookmarklet

Our Hello World! Bookmarklet is very simple. Here is the
java script:'Hello, World!'
Copy and paste the above simple line on to your browser’s URL bar and
press enter.

Couple of points to note about the Bookmarklet we just wrote
• The URL start with the key word java script: as like protocol
http, ftp etc. This is allowed especially as part of the
Javascript specification. All Bookmarklets start with this key
word. Anything that follows is the complete Javascript.
• Bookmarklets always run in context with the currently loaded
page’s HTML DOM. In other words, bookmarklets can manipulate
the currently loaded html page without affecting the
actual content (source) of the html page.
• The length of the Javascript written is limited. So it is very
much required to write smart Javascript programs as possible.
Sometimes, it is not possible to write the required functionality
within the limitation, then try using the Javascript crunching.
That is the reason most of the Bookmarklets are using
single letter variables.
• Bookmarklets need to be written in a single line though we
have multiple statements to be written in Javascript. Just remove
the line breaks in your Javascript code. Such line breaks
do not add any value. This is because browser URL text box
accepts a single line of text and removes any extra lines.
• You are allowed to use any of the Javascript APIs supported
by the browser. This is the main reason why some of the
bookmarklets working in a browser fail to work in other

Online Reference

Add more Bookmarklets examples if you know of them. There are a number of them being used now a days.

This post has been edited by bhandari: 11 February 2008 - 11:45 PM

Is This A Good Question/Topic? 0
  • +

Page 1 of 1