Bookmarklets: Informations on the Page

Everything about a web page may be displayed thanks to a list of functions we will create in the form of bookmarklets, links containing JavaScript code that is added to bookmarks.

These codes do not work if the page is in a frame, which also is becoming scarce.

All browsers

Number of links in the page

Makes use of the link property of document.

javascript:alert(document.links.length+' links')

Images without alt attribute

Another design tool, this bookmarklet indicates missing alt attributes.

For demonstration purposes, I have incorporated two images on this page... The first beeing without alt attribute should display null, but the second has one that is the title of the image: "Prado beach."

Prado beach

javascript:{
var x='';
for(i=0;i<document.images.length;++i)
{
    x+=document.images[i].getAttribute('src') + "=";
    x+=document.images[i].getAttribute('alt')+  '\n';
};
alert(x);
}

Origin of the page

Displays the page that has been entrusting the current page, or displays null when the URL was typed directly into the address bar of the browser.

javascript:alert('Origin: ' + document.referrer)

Firefox and Internet Explorer

Last update date

The lastModified attribute of the document object is used. This is not a standard attribute and it does not work with all browsers. It is implemented in Firefox and Internet Explorer.

Code of the bookmarklet:

javascript:alert('Last modified: '+document.lastModified);

The same code can also be placed in the body of the page to indicate to visitors when the document was last updated:

<script type="text/javascript"> document.write("- Last modified " + document.lastModified); </script> 

Firefox

Counting of words in a selection

Give the number of words in a text you've selected on the page.
Can not operate on the entire page as reading the content of the page returns HTML code with all the tags.

Uses getSelection() of the document object that is not standard and can not work with all browsers. Does not work with Internet Explorer but as a development tool, it is especially important that it be recognized by Firefox.

See also

© 2009-2012 Xul.fr