Home | Hardware | Internet News |Web Hosting |IT Management |Network Storage
LinuxPlanet
Search 
  Power Search | Tips 

 Front Door
 Discussion
 LinuxEngine
 Opinions
 Reports
 Reviews
 Tutorials
 News
 Technology Jobs

 Browse by subject.
Free Newsletter

Linux Planet
Linux Today
More Free Newsletters

Be a Commerce Partner


















internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

Print this article
Email this article

   LinuxPlanet / Tutorials







Roll Your Own Custom Bookmarklets In Firefox, part 2
Javascript Bookmarklets

Akkana Peck
Thursday, October 23, 2008 11:25:40 AM

In the last installment, I talked about the simplest form of "bookmarklets": bookmarks defined by Keywords and user-defined strings.

But you'll more often see the term "bookmarklets" used for a different sort of bookmark: those that execute Javascript code.

Javascript bookmarklets have been around since the early days of Javascript. They're possible because Firefox and most other modern browsers (except Konqueror) offer the special protocol "javascript:" to let you execute bits of javascript code directly.

For instance, try typing this into Firefox's URL bar:

javascript:alert('Hello, world!')

You've just executed some javascript code (Figure 1), of the sort you might include in a web page. But since it's packaged as a URL, you can bookmark it. That's a Javascript bookmarklet.

But what makes the javascript: protocol really useful is that the code is executed as if it was part of the current page. That means that you can access the information on the page, or even make changes to it. For example, try typing or pasting this URL:

javascript:void(document.body.style.color=prompt('Color?','green'))

The browser keeps the current page loaded. But in addition, a dialog pops up asking you for a color. Choose a color and click OK -- and the text of the current page changes (Figure 2). To turn it black again, use this link or click Reload.

Next: Useful Shortcuts Galore »

Skip Ahead

1 Javascript Bookmarklets
2 Useful Shortcuts Galore
3 Sandwiches, Functions, and More Bookmarklets
Figure 1
Figure 1 "Hello, World!"

Figure 2
Figure 2





Linux is a trademark of Linus Torvalds.


internet.com home | search | help! | about us

Jupiter Online Media

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers