Anthony's Java Bookmarklet
Show my Bookmarks
Show bookmarklet pageBlog Bookmarklets
Bookmarklets
From IRT.org
Bookmarklets are simple tools that extend the surf and search capabilities of Netscape and Explorer web browsers.
Steve Kangas - "Chief of Rocket Science" - Bookmarklets.com
Introduction
Here is something novel: using JavaScript to make your web experience more enjoyable, when you decide, and with what you want to do - rather than site specific JavaScript code that performs what the web author wants to do.
Wherever you browse the WWW, the chances are you'll come across a site that does something you don't like: opens new windows, displays white text on a black ground, etc. Until you've visited the site, you'll not know what it is that you'll not like. And once you've visited, its too late to change anything.
Wouldn't it be nice to actually alter the look of a site, extract data from a page, search the web and navigate in new ways?
This is where JavaScript Bookmarklets come in. The Bookmarklets.com web site run by Steve Kangas, uses a JavaScript feature not often demonstrated. Since the introduction of Netscape Navigator 3.x and Microsoft Internet Explorer 4.x, it has been possible to use a JavaScript URL in the form javascript:code in the location bar on all platforms: Windows, Mac, Unix etc.
If you are using one of the appropriate browsers, why not type the following into the location bar right now:
javascript:alert('Hello World') |
If you are using one of the appropriate browsers, and have JavaScript enabled, then you should see a JavaScript alert window with the words "Hello World". Notice how the location of the current document is not changed. This allows us to invoke JavaScript code on the current document without changing the documents location, and without requiring special access privileges to the documents site.
For example, to find out the current documents title, we can use the following JavaScript URL:
javascript:alert(document.title) |
Which should display "JavaScript Bookmarklets".
Making bookmarklets
If you regularly visit a particular web site, that, say, has a bad choice of background color. Perhaps you find it hard to read the text. Wouldn't it be great to be able to change the background color with out too much hassle? Well the following JavaScript URL would change the background color of the current document to white:
javascript:void(document.bgColor='#FFFFFF') |
However, after typing that out a few times, you might find yourself putting up with orange text on a red background. This is where the bookmarklet idea comes into its own.
Why not simply bookmark the JavaScript URL?
Indeed, why not? There is no reason not to. The JavaScript code, being part of the URL, will be safely stored in your bookmarks file. The JavaScript code cannot cause any problems (at worse it will simply generate an error message), it is small and effective, and it is only invoked when you choose the bookmark from your bookmark or favourites list.
But how do you bookmark a JavaScript URL? If you bookmark the effects of a typing in a JavaScript URL, then all you'll do is bookmark the current document.
This is simple. Just create a temporary page with the JavaScript URLs as complete hypertext links. For example:
<A HREF="javascript:void(document.bgColor='#FFFFFF')">White background</A> <A HREF="javascript:void(document.bgColor='#000000')">Black background</A> |
which looks like:
White background
Black background
and then just bookmark the above links:
- Netscape Navigator - Point at bookmarklet link. Press down (right) mouse button and choose "Add Bookmark".
- Microsoft Internet Explorer:
- Windows - Press down (right) mouse button and choose "Add to Favorites"
- Mac - Point at bookmarklet link. Hold down mouse button and choose "Add Link to Favorites"
For Netscape on the Mac and some Unix platforms, it may be necessary to rename the bookmarklet (since Add Bookmark lists the javascript URL as the name of the bookmark instead of the link text).
You'll now have two bookmarklets which can be used to alter the background color of any web page.
Unlike normal bookmarks, which include the documents title text, the bookmarked links use the link URL as the description of the bookmark, however, once bookmarked it is possible to manage/edit your bookmarks to give them a more user friendly description.
Why and when to use the void
The void operator discards the value of its operand and returns an undefined value. It is often used within links using the javascript: protocol to ignore the results of expressions. For example, when using the window objects open method, a reference is returned to the newly created window. This is usually used as a window handle. However, when used in a link, the returned window reference will cause the browser to display the returned result (normally '[object Window]') in the current window, thus overwriting the original contents. Using the void operator stops this from occuring:
<A HREF="javascript:void(window.open('about:blank', 'windowName', 'width=100,height=100'))">about:blank</A> |
Which produces:
Frame Compatibility
Bookmarklets act on the windows document, this means that if the window contains a frameset then there is a possibility that a bookmarklet will fail to achieve its objective, e.g. changing the background color, as it will attempt to change the background color of the window and not one of the framed documents. It just depends on what the bookmarklet is attempting to do. For example, a bookmarklet to place the URL of the window in the body of an email message would work perfectly:
<A HREF="javascript:location.href='mailto:?SUBJECT=' + document.title + '&BODY=' + escape(location.href)">Send Location</A>
Which produces:
It is possible to make bookmarklets compatible with frames - although you'll probably want one version for non framed pages, and another for framed pages - you just need to add frame navigation to your bookmarklets. For example, to change the background color of any frame within a frameset, you could add a prompt to confirm which frame you wish to change:
<A HREF="javascript:n=top.frames.length;if(n>0) {f=prompt('Which frame? [1-'+n+']','');if (f>n) {alert('Out of range!')} else {void(top.frames[f-1].document.bgColor='#FFFFFF')}} else {void(document.bgColor='#FFFFFF')}">White background</A> <A HREF="javascript:n=top.frames.length;if(n>0) {f=prompt('Which frame? [1-'+n+']','');if (f>n) {alert('Out of range!')} else {void(top.frames[f-1].document.bgColor='#000000')}} else {void(document.bgColor='#000000')}">Black background</A> |
Which produces:
White background [Frame compatible]
Black background [Frame compatible]
It's also possible to write a recursive script that descends through the frames. For an example, see the code for Page Freshness (Frames version) at http://www.bookmarklets.com/tools/frames.phtml#pgfrshfrm
Browser Compatibility
As you are no doubt aware, Microsoft and Netscape have different implementations of JavaScript and the Document Object Model, therefore it is possible to write bookmarklets that will work with one browser but not another.
It is also possible write bookmarlets that will only work correctly on the latest browser versions. For example, to get feel for how long a document is the following bookmarklet will calculate how many windows the current document fills:
<A HREF="javascript:alert('The document fills about ' + Math.round((document.height*document.width) / (innerHeight*innerWidth)) + ' windows (at current window size)')">Document size</A> |
Which produces:
As it stands it will only work in Netscape Navigator 4+, but another bookmarlet could be written for Microsoft Internet Explorer 4+:
<A HREF="javascript:alert('The document fills about ' + Math.round((document.body.clientHeight*document.body.clientWidth) / (document.body.offsetHeight*document.body.offsetWidth)) + ' windows (at current window size)')">Document size</A> |
Which produces:
You just bookmark the appropriate bookmarklet for your browser, although if you are adventurous, you could always create bookmarklets that handle both browers at once:
<A HREF="javascript:if (document.all) {alert('The document fills about ' + Math.round((document.body.clientHeight*document.body.clientWidth) / (document.body.offsetHeight*document.body.offsetWidth)) + ' windows (at current window size)')} else {alert('The document fills about ' + Math.round((document.height*document.width) / (innerHeight*innerWidth))+' windows (at current window size)')}">Document size</A> |
Which produces:
Document size (MSIE4+ and NN4)
Conclusion
As Steve himself says "the limit on the number of characters [in a bookmark] is difficult to answer", although "Netscape on Macintosh will not accept bookmarks longer than 507 characters, and may have trouble with bookmarks longer than 255 characters." Currently Steve uses a maximum of 256 characters for all the bookmarklets at Bookmarklets.com. Although he hopes to be able to extend this self imposed limit based on feedback received to 1000, 2000 and then perhaps 4000 characters.
This article has only been a short introduction into the use of bookmarklets. Bookmarklets can be used to scroll through a document, hide and display images, alter the text font and color (MSIE4+ only), manipulate selected regions of text in the document, examine and manipulate the links in a page, manipulate windows - they are limited only by your own imagination.
My personal favourite is the following simple bookmarklet that resizes the window to 640x480 pixels (so that I can check what a page looks like at a smaller resolution):
<A HREF="javascript:resizeTo(640,480)">Resize (640x480)</A> |
Which produces:
Simple, but extremely effective.
I would strongly suggest visiting the Bookmarklets.com web site run by Steve Kanga, as there are over 150 bookmarklets just waiting to be bookmarked.
Sourced from LucDesk
Bookmarklets are links, but they do not link to web pages, they link to a simple script. To keep a bookmarklet, just bookmark it or drag it to your links bar. (Please note: Not all bookmarklets work on all browsers.)
- Search Google
- Search Teoma
- Search AllTheWeb (Source: dooyoo-uk)
- Dictionary Lookup (Source: centricle)
- Thesaurus Lookup (synonyms and antonyms) (Source: centricle)
- Search TechEncyclopedia
- Find Articles
- List all links on page in new window
- Alexa Snapshot (Source: Woodster.com)
- Page Weight (Source: Woodster.com)
- Check Uptime (Netcraft) (Source: centricle)
Sourced from Woodster.com
Site Data
Netcraft...Alexa Snapshot...
Google Related...
Whois...
Cookie?
Validate Site
W3C HTML Validator...W3C CSS Validator...
Selected Text
Search Google...Define...
Thesarus...
Grab...
Manipulate Page
Grayscale the pageMissing ALT Tags
Loose CSS
Zoom +
Zoom -
Turn on Borders
Page Weight
Show DIVs
Page Freshness
Analyze Images
Page Weight & Speed...
View CSS...
View Scripts...
View Graphics...
Misc
ResizeNext Blog
Bookmarklets/Favelets that work in Safari from Andy Budd
Amazon Bookmarklets
- Amazon.com book search
- Amazon.com general search
- Amazon.co.uk book search
- Amazon.co.uk general search
General Web Surfing
- MT post
- Convert long URL to "tinyurl"
- Email URL
- AutoFill Anonymous
- Make form Get
- Bablefish bookmarklet
- Google Translate!
- Full Screen
Web Development
- W3C (X)HTML validator
- W3C CSS validator
- Beta Validate
- Fussy Parsing
- Toggle Linked CSS
- Bobby check A
- Bobby check AA
- Bobby check AAA
- Resize browser to 640x480
- Resize browser to 800x600
- Resize browser to 1024x768
- PHP Function
- Show divs with colour
- View Cookies
- Web Page Analyzer
SEO
Bookmarklets for Opera sourced from Phil Burns
Navigation
Open all Links in New Windows Opens all the links on the page in new windows and sends them to the background
Split Frames into Windows The windows will have the original frame size : from - bookmarklets.com.
Open Previous in New Window Only works if the Previous is in the same domain
Open Next in New Window Only works if the Next is in the same domain
from - Me.
Searching
Search this Domain. Very cool. Promts for a string, then does a Google advanced search in current domain.
Search ODP (New Window) from - ODP (dmoz.org) editors bookmarklets.
Search ODP in Background from - Phil Burns.
Search Hotbot (New Window) from - Rijk Van Geijtenbeek.
Links To this Page - AltaVista from - Rijk van Geijtenbeek.
Search for current page in www.archive.org from - Tobias Boyd.
Search google groups (New window) from - An opera.general poster I think
Checking Code Validity
Validate at WDG from - Rijk van Geijtenbeek.
Validate HTML at W3C from - Rijk van Geijtenbeek.
Validate HTML at W3C (In Background) from - Me :).
Validate all frames HTML W3C from - Me.
Validate CSS for page at W3C from - Phil Burns. Finally my own one :)
Validate CSS for page at W3C (In Background) from - Phil Burns. Another :)
Validate all frames CSS W3C from - Me.
Validate HTML & CSS at W3C (In Background) Opens two windows from - Phil Burns. Another :)
Page Data
Document Info Very nice... shows URL, hostname, the URLs of all frames (clickable), modification date, referrer, hash (both if provided only), lists all links and all images (both clickable), all in a new popup window. By - Roland Reck.
URL
',thiswin.document.URL,'
Hostname
',thiswin.document.location.hostname); write('Frame URLs
'); var pw=thiswin.parent;var i = 0;while (i');}; {write('
Last modified
',thiswin.document.lastModified,'Referrer
',thiswin.document.referrer,'Cookie
',thiswin.document.cookie,'Hash
',thiswin.document.location.hash,'Links
');};var i = 0;while(i');};{write('
Bilder
');}; var i =0;while(i');};void(close())}">Document Info 2 Similar to the above but re-written by Roland for Opera 7 Read Cookie for Site from - bookmarklets.com I think.
Check Document Last Modified from - Maurizio Berti & Rijk van Geijtenbeek.
Who is from - Jesse Ruderman
Check site server from - Jesse Ruderman
Show HTTP headers from - Jesse Ruderman
Window widgets
Resize Window to 1024 x 768 Me.
Resize Window to 800 x 600 Me.
Resize Window to 640 x 480 Me.
Miscellaneous
Google Translate (English) from - Partially Correct
List Email Links from - bookmarklets.com
Number of Links from - bookmarklets.com
Go To Random Link from Page from - ODP (dmoz.org) editors bookmarklets.
List All Links on Page from - ODP (dmoz.org) editors bookmarklets.
Send Location This one may be of particular interest to those that want to send pages by email. from - ODP (dmoz.org) editors bookmarklets.
AutoFill Anonymous Fills out forms as anonymous.
from - ODP (dmoz.org) editors bookmarklets.
Bookmarklets Editor Creates a window to make and test your own bookmarklets in.
from - ODP (dmoz.org) editors bookmarklets.
Show All Images in New Window - Modified from bookmarklets.com
PAS Complaint - Send a complaint about a webpages code to all mailto links on a page ;-) from - Me
Bookmarklets from Centricle
- Ruler 1.2 (info)
- Show Specific Elements (info)
- Highlight Elements [MacIE] (info)
- Highlight Elements [Gecko/KHTML] (info)
- Google [selected] (info)
- Show IDs (info)
- User CSS (info)
- Maximize IE (info)
query web tools
There's nothing particularly innovative here, just some things I threw together for my own convenience. They simply query existing tools on the Web directly from the browser, so if you find them to be useful, drag to your browser's toolbar & enjoy.
They should all work in for IE 5 & up and Mozilla, on both Mac & Windows.
Search via Prompt:
- Search Google
- Search Google Groups
- Search Google Images
- Google Current Site
- Dictionary Lookup
- Thesaurus Lookup
- Search PHP.net
- Lookup PHP Function
- Search eBay
- Search OLGA
- Search IMDB
- Define Acronym
Search for Selected:
- Search Google
- Search Google Groups
- Search Google Images
- Google Current Site
- Dictionary Lookup
- Thesaurus Lookup
- Search PHP.net
- Lookup PHP Function
- Search eBay
- Search OLGA
- Search IMDB
- Define Acronym
Webdev Tools:
Dev Tools via Prompt:
Bookmarklets from Sean Willson
- search
- search with prompt
- tools
- check link on webpage
- check website uptime
- disable stylesheets
- resize browser 640x480 vga
- resize browser 800 x max screen height
- resize browser 800 x 600 svga
- resize browser 1024 x max screen height
- resize browser 1024 x 768 xga
- ruler 1.2 (on screen ruler)
- show image sizes
- show alt info
- tidy html
- validate html
- validate html in new window
- validate typed url
- validate typed url in new window
- validate css
- view http headers
- display webhost info
- babelfish - japanese to english
- babelfish - french to english
- babelfish - gernam to english
- babelfish - spanish to english
- babelfish - italian to english
Bookmarklets from Squarefree
- Link Bookmarklets: search links, linked images, etc.
- Form Bookmarklets: toggle checkboxes, enlarge textareas, view passwords, etc.
- Text and Data Bookmarklets: zoom images in, sort table, etc.
- Zap Bookmarklets: get rid of annoyances such as unreadable color combinations, Flash, and blind links.
- Web Development Bookmarklets: debug web pages and experiment with new code.
- Validation Bookmarklets: check how well the code of a web page is written.
- Miscellaneous Bookmarklets.
- Search Bookmarklets.
- Search Engine Optimization Bookmarklets: search for backlinks, analyze search engine positions.
- Log Analysis Bookmarklets: analyze referer logs efficiently.
- Flash Bookmarklets: pause, rewind, and fast-forward Flash cartoons.
- Tipping Bookmarklet: send money to an e-mail address in a page.
- Color Bookmarklets: change all colors on a page at once.
- Keyword Bookmarklets for Scripters: type "jb document.body" to make document.body blink, etc.
- Site-specific Bookmarklets: fix annoyances on some sites I read.
- Bugzilla Bookmarklets: for people involved in the Mozilla project or other projects that track bugs using Bugzillas.
- Testing browsers: test features or stress limits of browsers.