Skip to content

Instantly share code, notes, and snippets.

@OrinZ
Forked from simonw/shorten-bookmarklet.js
Created June 23, 2009 02:55
Show Gist options
  • Save OrinZ/134325 to your computer and use it in GitHub Desktop.
Save OrinZ/134325 to your computer and use it in GitHub Desktop.
A bookmarklet to report the rev=canonical attribute if one exists, or alert if one does not.
/* bookmarklet for extracting rev=canonical if it exists, or simply notifying if one does not */
(function(){
var url=document.location;
var links=document.getElementsByTagName('link');
var found=0;
for(var i = 0, l; l = links[i]; i++) {
if (l.getAttribute('rev') == 'canonical' || (/alternate short/).exec(l.getAttribute('rel'))) {
found=l.getAttribute('href');
break;
}
}
if (!found) {
for (var i = 0; l = document.links[i]; i++) {
if (l.getAttribute('rev') == 'canonical') {
found = l.getAttribute('href');
break;
}
}
}
if (found) {
prompt('URL:', found);
} else {
alert('No canonical url found.');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment