Wednesday, July 20, 2005 automatic links

Update: Just call me Rube Goldberg. John points out that there's a much easier way to add links to than the over-engineered mess I describe below -- just use the blog macros to create the { link} + {permalink url} + {title} directly in your blog template. There's no need for Javascript code at all. Still, the Javascript can still be used to automatically generate links on non-blog web pages.

Yesterday, I linked to an article about using Greasemonkey, Firefox, and to help automate the process of adding Technorati Tags to your blog articles. Today, I explain how to easily create a link to post your article to, a relatively new "social bookmark" service. You don't need Greasemonkey or the Firefox browser or even -- this code should work with any blogging software or service.

If you grok, skip to the code and examples.

What is provides a method for users to categorize their favorite websites into ad-hoc categories. These users assign "tags" or categories to the website and enter them into's database. Think back to the early days of the web when Yahoo first came out. Yahoo used human editors to categorize websites into categories., on the other hand, is a social network that allows anybody to tag or categorize their favorite websites. Furthermore, there are no predefined tags; the tag keywords are chosen and created by the users themselves.

This practice of collaborative tagging is called "folksonomy," after "folk" (for normal, everyday people) and "taxonomy" (the practice of organizing things in to groups)

Why become

Because of the voting/popularity aspect of, many users report search results that are more relevant than those from standard search engines. As tagging systems such as Technorati, Flickr, and become more popular, they will become increasingly important in driving traffic to your website.

How to be

Delicious users typically add a bookmark to their browsers linking to Javascript at When the user visits a web page he likes, he clicks the delicious bookmark, he is redirected to a form at, enters his tags and submits the website to

Web pages can also have a link on their pages to simplify the process for their visitors. I've written a small snippet of Javascript that creates this link for you on every page you include this Javascript. I also have a PHP version if you're concerned about users who disable the script.


First of all, a disclaimer: This is the first time in my life I've written Javascript, so if I've made any horrible mistakes please let me know in the comments.

Here's the basic code that will create a link to's site submittal form, using the current URL and page title.

<script type="text/javascript">
  var ref="" + document.URL + "&title="
  var title = document.title
  newtitle = title.replace(/ /g,"+")
  fullref = encodeURI(ref + newtitle)
  document.write("<a href=\""+fullref+"\">")
  document.write("Make me")

This is a very basic Javascript program. It builds the hyperlink anchor to the form, with the current URL and document title added as the values for the url and title parameters. The string replace method replaces all spaces with the plus sign. encodeURI replaces illegal URL characters in the query string with valid characters.

You can add this Javascript code to any web page, whether it's a blog or not. If you want to do this on the server side, here's the PHP equivalent.

function delicious($pagetitle) {
// This function will "Make Me Delicious"
// by inserting URL-specific link to's
// tag post URL.
// Input parameter $pagetitle is the title of the page.
$newurl = 'http://'.urlencode($url);
$newtitle = urlencode($pagetitle); // make the title URL friendly
echo "<br /><a href=$newurl&title=$newtitle>
Make me delicious</a>.<br />";

Like the Javascript example, this code will create a link to's posting form. Unlike Javascript, the server-side PHP cannot determine the title of the page (unless you want to read the page and parse the title yourself), so the title is passed as an argument to the function delicious(). This function is called at the place on your web page you want the link. example

Whatever blogging software you use, you want to put the code in your template so that links to del.icious are automatic. Below is how I added the Javascript to my bicycling blog. I put the code right after the blog article text (identified by <$BlogItemBody$>) and right before the "posted-by" footer. You'll notice the Javascript code is slightly different from the general example above -- I make use of macros. BlogItemTitle expands to the title of my article because the HTML page title may be something a little different. Also I use BlogItemPermalink because this Javascript may be running from the index page of the blog or from the "Permalink" page -- I want to be sure the right page gets tagged.

<script type="text/javascript">
var ref="" + "<$BlogItemPermalinkUrl$>" + "&title="
var title = "<$BlogItemTitle$>"
newtitle = title.replace(/ /g,"+")
fullref = encodeURI(ref + newtitle)
document.write("<a href=\""+fullref+"\">")
document.write("Make this")

If you use the PHP version instead and your blog is hosted on a PHP-enabled host, calls to the delcious function are made like this to ensure you get the article title: delicious("<$BlogItemTitle$>). Note that the PHP version will only work on the Permalink page, so make sure the PHP code is wrapped within the tags <ItemPage> </ItemPage>

If you make use of this code, please drop me a line in the comments below.


Blogger John said...

There's a way to do this without javascript too. See my post at Freshblog.

11:43 AM  
Anonymous Jolly said...

Nice post I am going to look around your site seems you have some great stuff.

4:58 AM  
Anonymous Anonymous said...

I learned more about online money making system through your blog. I am having a nice blog about the same keyword when was I experienced about online making money through this blog.

Make Money Online

Free part Time Jobs

Part Time Jobs

10:13 PM  
Anonymous Complete SEO Packages said...

Professional SEO Expert employs Buy One way Link & Guaranteed Link Building, for details visit

1:57 AM  
Anonymous seo packages said...

Thanks for giving good idea and sharing java script with us. I would like to try this now.

3:31 AM  

Post a Comment

<< Home