Assume the Position

Saturday, January 11, 2003
 
How'd I Get Here? II. I previously posted a small, single-line javascript Favorite/Bookmark to pop up an alert showing the page that referred you to the page you are viewing. I also wrote, "I fooled around with a few versions that print the URL in a new window, goto the URL, copy the URL to the clipboard, etc., but they were all rather clunky and I decided I like this simple one the best." Well, at least for Internet Explorer users, I've got one now that will let you copy the referrer to the clipboard.

This version will pop up a message box asking if you want to copy the displayed referrer to the clipboard. If you just wanted to see the referrer as a reminder you can press "Cancel;" otherwise, pressing "OK" completes the copy and you will be able to paste the referrer data into a link, the address bar, or elsewhere.

Installing it is the same as the last time. Just right-click on the "Copy Referrer To Clipboard" link and pick "Add to Favorites" on the pop-up menu. You can also drag the link to your links toolbar. IE might pop-up a warning that the favorite may not be safe, just press "Yes" to finish adding it. You can see most of the code itself in the status bar when the cursor is over the link (it's too long for all of it to fit) and I include the full code for the link right below it. If you left-click on the link itself it will work and show you how you got here (if the "Open off-site links in new windows" box at the top left of the page is checked, a blank window might open, also).

Copy Referrer To Clipboard

Link code:
<a href='javascript:if(confirm("Copy this referrer:\n\n"+document.referrer+"\n\nto the clipboard?"))clipboardData.setData("Text",document.referrer);void(0)'>Copy Referrer To Clipboard</a>
There are a few minor things to note.
  • It is probably IE specific. I don't know if Netscape, Opera or others support the clipboardData object.

  • It won't always show a URL because some redirects strip referrer information, or you might have directly opened the page from your favorites list or typed the URL into the address bar, so there was no referrer, etc. If you click "OK" in those instances the clipboard will be cleared (emptied) when the nul (blank) referrer data is copied to it.



Original content copyright © 2002-2005 Lynxx Pherrett. All rights reserved.