0x0Lab Blog Just another damn blog

22Jun/10Off

Remove http referrer bookmarklet and Safari5 extension

Let's go through the creation of a bookmarklet that removes the http referrers from all links in a page. This has been tested in Safari and Firefox.
This will only work on <a> tags in pages.
Essentially we want to perform the following for all the <a> tags in the page:
Remove all "onmousedown","onmouseover","onclick" events.
Add an onclick event that will point the browser (using document.location) to a data url that contains a javascript pointing the browser (again using document.location) to event.currentTarget.href :) .
This way no referrer will be send to the visiting link.
The loop we will need to execute is:

for(var i=0;i<document.getElementsByTagName("a").length;i++){
document.getElementsByTagName("a")[i].removeAttribute("onmousedown");
document.getElementsByTagName("a")[i].removeAttribute("onmouseover");
document.getElementsByTagName("a")[i].removeAttribute("onclick")
;document.getElementsByTagName("a")[i].setAttribute("onclick","
document.location='data:text/html;charset=utf-8,%3C%21DOCTYPE%20html%3E%3Chtml%3E%3Cscript%3Edocument.location%3D%27'+
escape(event.currentTarget.href)+'%27%3B%3C%2fscript%3E%3C%2fhtml%3E';return false;");
}

Which can be turned into the following bookmarklet: Remove Referrer

Using the same code I've also made a Safari 5 extension which can be downloaded from here: Referrer Remove
The extensions adds a context menu called "Remove Referrer" that can be found by right-clicking on a page.
Note: You will need to enable the extensions.

Posted by cirrus

Filed under: MacOSX Comments Off
Comments (2) Trackbacks (0)
  1. You forgot the “document.getElementsByTagName(“a”).length; i++ )” part. Nevertheless good job!

  2. @gtg: oops forgot to replace < with its html encoded counterpart. Should be ok now.


No trackbacks yet.