Adding a DotNetKicks image via Javascript

About DotNetKicks

DotNetKicks is a nice social bookmarking system (like Digg, Reddit, etc.) that's specific to .NET development issues. Users submit cool links, other users vote on it, popular links show up the front page and in an RSS feed. It lets you know what's going on in the .NET world right away without having to spend every second of the day scanning thousands of blogs.

Kick It!

One of the cool features is an image which shows the number of "kicks" a page has received. The image links back to the vote page, so you can just click the "kick it" button to vote. Neat. Here's a button from a recent post I did about connection string protocols:

Adding a Kick It button via Javascript

Some blog engines support the "kick it" button. The system I'm using - weblogs.asp.net - has a "kick it" link on every post, but doesn't show the images. It's a hosted system, so the only real way to tweak things is via CSS and Javascript. I hacked together some Javascript to add the kick count button. This is pretty generic, with the exception of the 'postToolbar' ID. You'll want to replace that with DIV (or some other container element) on your page.

Since the Kick counts are based on specific posts, this only displays the image when you're viewing an individual post.

UPDATE: Changed from Submit to Kick url, and changed the submitted url so it doesn't include the querystring.

addLoadEvent(AddDotNetKicks); function addLoadEvent(fn) { if (window.addEventListener) window.addEventListener('load', fn, false) else if (window.attachEvent) window.attachEvent('onload', fn); } function AddDotNetKicks() { var insertLocation = document.getElementById('postToolbar'); if(insertLocation) { var currentPageUrl = document.location.protocol + "//" + document.location.host + document.location.pathname; var dotnetkicksLink = document.createElement('a'); dotnetkicksLink.href = 'http://www.dotnetkicks.com/kick/?url=' + currentPageUrl; var dotnetkicksImg = document.createElement('IMG'); dotnetkicksImg.src = 'http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=' + currentPageUrl; dotnetkicksImg.border = 0; dotnetkicksLink.appendChild(dotnetkicksImg); insertLocation.appendChild(dotnetkicksLink); } }

To do and notice

The DotNetKicks services are based on a page URL, so the Javascript pulls that in using document.location properties.

The script works by appending HTML elements to an existing DIV with an ID of 'postToolbar'. That element won't exist when the page is being loaded, so we need to wait on running the Javascript until loading is complete. I'm using the addLoadEvent to attach a load handler. I wrote more about that in a previous post about adding a logo to SQL Server Reporting Services reports.

Published Thursday, March 08, 2007 2:35 PM by Jon Galloway

Comments

# re: Adding a DotNetKicks image via Javascript

Very nice, thanks for creating this Jon.

Friday, March 09, 2007 10:48 AM by Gavin Joyce

# re: Adding a DotNetKicks image via Javascript

Many thanks was very usefull.

Friday, March 09, 2007 1:19 PM by Adel

# re: Adding a DotNetKicks image via Javascript

You're a star and I get to kick you!

Wednesday, March 14, 2007 5:23 AM by Haacked

# re: Adding a DotNetKicks image via Javascript

Du musst ein Fachmann sein - wirklich guter Aufstellungsort, den du hast!

Wednesday, March 14, 2007 9:33 PM by ...

# re: Adding a DotNetKicks image via Javascript

Very useful stuff!

Wednesday, August 01, 2007 6:12 AM by dotnetUncle - .NET Interview Questions

# New DNK Features: Kick Spy

New DNK Features: Kick Spy

Monday, September 17, 2007 7:58 AM by Gavin Joyce's Blog

# New DNK Features: Kick Spy & Shoutbox

This week there have been over 100 commits to the DotNetKicks open source trunk. Some fantastic new features

Monday, September 17, 2007 8:01 AM by Gavin Joyce's Blog

# re: Adding a DotNetKicks image via Javascript

è difficilissimo trovare il costruttore di Image / window.document.images[] per ie è undefined x netscape e mozilla è [HTMLImageElement]

purtroppo mi devo sorbì argomenti che non c'entrano nulla!!!!!!!!!!!!!!!

Friday, December 07, 2007 5:36 AM by fabrizio

# DotNetKicks PlugIn for Windows Live Writer

I've been using some javascript snippet that generates a DotNetKicks KickIt image for a blog post. I found the javascript to insert the KickIt link in a post by Jon Galloway . (Thanks Jon!) I tweaked his javascript to suit my needs and it works well.

Wednesday, April 30, 2008 2:26 AM by JohnPapa.net

# DotNetKicks PlugIn for Windows Live Writer

I've been using some javascript snippet that generates a DotNetKicks KickIt image for a blog post

Wednesday, April 30, 2008 2:35 AM by John Papa [MVP C#]

Leave a Comment

(required) 
(required) 
(optional)
(required)