Robust, accessible HaloScan comment links

The scheme that HaloScan currently uses to load your comment counts and links, with a <script src=””> that loads the comments counts plus a function for the count and a function to open the popup, and then a link that consists of a javascript: link with the comment count function call writing the link text, is fine for casual use, and certainly simpler for them to maintain and support: two minimal bits of script for you to copy and paste, and that’s it.

However, if people who are old enough to know better are going to use it, it needs a little work: it should be possible to access the comments without javascript, and if the script can’t be loaded (whether because the server is down, or just because of routing troubles between one reader and the server), it shouldn’t take the page down with it or throw a script error for every single post. Here’s how to robustify and de-script-depend Haloscan:

Before the <script src=””> tag, you need to initialize the array for the comment count, so that if the script loads it will be overwritten, but if it doesn’t then trying to access the array won’t throw an error. You also need to define your own function to write the comment link text, both so you won’t be calling an undefined function once for every post if the remote script fails to load and also so you can put some text in there for people without javascript:

<script type="text/javascript">
var hs = new Array();
function myCount(id){
if (hs[id]){
if (hs[id] == 1){
document.write(" (1)");
} else {
document.write("s (" + hs[id] + ")" );
} else {
document.write(" (0)");
<script type="text/javascript" src=""> </script>

Then, for your comment link, rather than:


<a href="javascript:HaloScan('<%itemnum%>');"><script type="text/javascript">postCount('<%itemnum%>'); </script></a>


<a href="javascript:HaloScan('<$BlogItemNumber$>');"><script type="text/javascript">postCount('<$BlogItemNumber$>'); </script></a>



<a href="<%itemnum%>" onclick=",'','directories=0,height=450,width=420,location=0,resizable=1,scrollbars=1,toolbar=0');return false;">Comment<script type="text/javascript">myCount('<%itemnum%>'); </script></a>


<a href="<$BlogItemNumber$>" onclick=",'','directories=0,height=450,width=420,location=0,resizable=1,scrollbars=1,toolbar=0');return false;">Comment<script type="text/javascript">myCount('<$BlogItemNumber$>'); </script></a>

(In both sections replacing USERNAME with your HaloScan username, of course.)

Then someone without javascript or with it disabled sees just a normal link with the text “Comment”, someone with javascript sees a normal link in the status bar with a comment count in the link text, but gets a popup window, and someone like me who routinely either control-clicks or right-clicks and selects “Open in new tab” gets something other than a javascript error. If the script doesn’t load due to some momentary network problem, you still have perfectly usable links, where with the original if the script doesn’t load for someone then the comment links are dead until they reload the page and get the script to load.

It does have its disadvantages for HaloScan, in that it lets Google see your comment links (easy enough for them to stop with a robots.txt file) and prevents them from doing lightweight load balancing and redirection by changing the URL that they put in the popup opening function, but luckily the few people who’ve actually read this far aren’t likely to be much of a problem for them.


Comment by Robert Scoble #
2002-12-12 15:31:51

Thanks for your help! I really appreciated it. My comments now rock!

Comment by Jeevan #
2002-12-15 16:27:46

Ever since I had read your post on how comment links should be more accessible a couple months ago (I think), I’d been planning on rewriting the Javascript loader but never got around to it as there were some other things that needed to be completed first. The Haloscan front page has however been using a method similar to yours ever since I read your first post on accessible comments.

Thanks for the little howto. I’ll point people this way from the site after I add the appropriate robots.txt entry (and eventually modify the code in the Javascript loader itself).

Comment by Phil Ringnalda #
2002-12-15 16:45:27

Yeah, I thought you would probably need to keep Googlebot’s prying eyes away – not only does it add a ton of traffic (especially if it decides that you are a good source of fresh content, so it comes by every night), it also make you a huge spam target. If you keep Google out you’ll only have to deal with really stupid spammers, which is likely to be a lot easier than dealing with the cunning ones.

Comment by James #
2003-02-18 17:15:34

Just wanted to say thank you. Cheers.

Comment by Jamie #
2003-02-27 17:52:23

Nice. This should stop the anti-popup software from blocking the comments windows from appearing !
Thanks !

Comment by Phil Ringnalda #
2003-02-27 21:26:26

Oh, I hate it when that happens. I’m not sure if it’s new since Mozilla/Phoenix started blocking popups, or I just didn’t notice before, but now when it blocks a popup from a javascript: link, if you click the link again, it allows it to open. Seems like a pretty good compromise, though I still tend to click the link once, and then just sit there wondering why nothing happened for a while.

Comment by roy #
2003-03-19 14:57:57

Thanks for the tip! I just tried it with Opera 7.0 and Phoenix 0.5 and it works great! With Opera I have it set to refuse pop up windows, so instead, the comments open in the same windows rather than just doing nothing.


Comment by Angel Cosmos #
2003-03-19 15:19:03

Thanks for writing this, I thought I was the only one having that ”error” problem ^.^; but I noticed that you only have instructions for radio and blogger. Will you be making a script to replace the comment replacement for greymatter? =/

Comment by Jeevan #
2003-03-19 18:55:12

Greymatter uses the internal tag {{entrynumber}} to generate the IDs so replacing every instance of <$BlogItemNumber$> in the Blogger example above with {{entrynumber}} should work.

Comment by Phil Ringnalda #
2003-03-19 19:20:19

Doesn’t Greymatter do its own comments?

Comment by Jeevan #
2003-03-19 23:06:02

Yes, I actually didn’t add Greymatter to the list initially for exactly this reason. But then people started emailing me to ask how they could use it anyway. Why? I’m still not clear.

Comment by Angel Cosmos #
2003-03-27 23:47:02

well for my situation, my crappy host doesn’t know how to fix the commenting with gm. when you click ”preview” or ”post” you end up downloading it as a file *grr*. I luv haloscan ^.^

Comment by Jeanetta #
2003-03-26 22:34:03

Using this fix, people who read my blog using IE 6 see ”Comment (0)” for all my comment links. It doesn’t seem to be a problem with older versions of IE or Netscape. Is anyone else having this problem? Anyone have a fix?

Comment by Phil Ringnalda #
2003-03-26 23:15:50

In the script tag that loads the counts from Haloscan, you’ve got

script type="text/javascript "src=

with a space before the quote and none between the quote and the src. Looks like IE6 objects to that – I saved a local copy and moved the space to the other side of the quote, and it works fine.

Comment by Jeanetta #
2003-03-27 12:20:30

Thanks! That was easy to fix :-)

Comment by Alvy #
2003-03-29 10:51:23

First of all, thanks for the hack, it’s great.

Question: I don’t seem to understant how you can manage now it to get different text for 0, 1 or more (n) coments.

I mean, on Haloscan settintgs I used to have them (well, actually in Spanish) with the following text/settings:

0 – Do you want to be the first person to comment?
1 – There is one comment
n – Comments: N

but now something is not working. I just get (probably not from haloscan, but from the blogger template) only

’Comments: (n)’

either 0, 1 or n

Any ideas on this?

Comment by Phil Ringnalda #
2003-03-29 13:33:50

Two problems:

If you write the entire link text with Javascript so you can vary it all based on the number of comments, then rather than just having the static text ”Comment” outside the script tag in the link, you have to have a <noscript> section to give people without Javascript a link, which makes it a bit odd if you want valid HTML, since they foolishly require that noscript’s content be a block level element, even though a link can’t contain a block level element, so you end up having to say (line breaks added just so it would fit on the page):

<a href=””>
<script type=”text/javascript”>

to be valid, even though:

<a href=””><p>Comment</p></a>

would be invalid. That’s so silly, and annoys me so much, that I try to avoid using noscript inside a link.

Then there’s the problem of people with Javascript enabled, who load your page when Haloscan is momentarily unavailable. With my hack, they just get a link with the static text ”Comment”, and if Haloscan is back up by the time they want to comment on something, clicking the link will work. If you write the entire link with Javscript, then someone who loads the page when they can’t load your comment counts from Haloscan doesn’t get any comment links at all: for all they can tell, you shut off commenting entirely.

If minor outages and routing problems between readers and Haloscan are rare compared to the number of longterm outages, then not having a comment link at all when the counts don’t load might be better, so that rather than teasing people with a link that isn’t actually going to load the comments, you just don’t show anything, but my experience (with things other than Haloscan, since I’ve never actually used it on a page that I regularly load throughout the day, day after day) is that minor, temporary outages are common compared to longterm outages – you notice that the comment counts didn’t load, reload the page, they do, you shrug and forget it. If that was a new visitor who doesn’t know you have comments at all, he’s gone.

Comment by Sergio Fonseca #
2003-06-11 07:58:15

You can do this very easily. Just re-write the array function. Something like:

var hs = new Array();
function myCount(id){
if (hs[id]){
if (hs[id] == 1){
document.write(”Just one comment (1)”);
} else {
document.write(”A lot of F.. comments (” + hs[id] + ”)” );
} else {
document.write(”Smash your f. brain here!”);

Comment by Autumn May #
2003-06-21 08:55:53

Brilliant….and thanks a MILLION..I stumbled on here, as a new blogger, wondering just what in the hell I wasn’t doing right and why in God’s name wasn’t I deserving of a simple, funtioning comments option, and this post saved me.

At a loss for more words. Hope u get the picture.

Comment by John #
2003-06-23 21:32:57

This might be a question you’ve already answered, but what do you do if you have a manual blog, where you have to provide the id numbers?

Comment by Phil Ringnalda #
2003-06-23 21:43:12

Come to your senses? No, kidding. (A sentence fragment that I’m afraid amuses me way too much.)

Unless I’m missing something, you just replace <$BlogItemNumber$> in the Blogger instructions with your manual id number, just like you do with the original style of links.

Comment by Anita #
2003-06-28 17:21:35

well, I used the blogger info for my Developer’s Corner Blog, using instead of
I think it works!

Comment by Anita #
2003-06-28 17:24:58


my comments didn’t show up on this page that I typed inside of some tags

OKay… blogger uses (tag)$BlogItemNumber$(tag)

For Developer’s Corner Blog, I replaced that with


:) my two cents

Comment by Anita #
2003-06-28 17:27:14

Now… I see the rules… duh

Comment by Phil Ringnalda #
2003-06-28 17:50:33

If I could figure some way of making them more obvious when you need them, the first time you comment here, without having them in the way all the time, I’d do it. Maybe I should slip them in between the textarea and the Post button for people who don’t have a cookie remembering their personal info, but leave them at the bottom for anyone who does.

Comment by Dean #
2003-06-28 21:22:32

Thanks, I was having trouble getting the code to work on desktop browsers but it work on my palm pda using a Japanese browser. Your javascript ended the trouble. thanks.

Comment by redandyellow #
2003-07-03 03:57:21

Hi Phil, can you make one of these for enetation? They are changing their network around so the last few days its been abit dodgy.


Comment by CrazyDave #
2003-10-05 08:35:26

I’ve only just come across this.
I modified it into an Enetation comments fix

Comment by Joel #
2003-07-08 20:45:05

I’m not sure what I’m doing wrong. On my test page I get both the pop-up javascript comments window AND the comments load into the full-size window as well. I have a manual blog.

Any thoughts? I gather either the popup should appear if everything is fine and javascript is enabled, with the main window remaining unchanged, OR, if there is a problem at Haloscan or javascript is disabled then the comments simply load into the main large window. Both happening I take is not the desired result.

Comment by Phil Ringnalda #
2003-07-08 21:58:09

Nope, that’s not at all the desired behavior ;)

The problem is the line breaks in the link, especially the one between ”return” and ”false;” – there actually aren’t supposed to be any line breaks in there at all, but it looks as though I changed something in my formatting that moved it from a sort of tolerable spot to a spot where it completely breaks things. If you just make that all on one line, from the <a clear out to the /a>, it should work fine.

Comment by Joel #
2003-07-09 05:22:48

Brilliant Phil, works like a charm!

Can I just clear up one thing, when popup killers are used, should the comments window still open in a small popup? I only ask because in Opera with popup killer on it opens into the main window, but in Mozilla the small popup still works with popup suppression on (maybe a change in preferences in Mozilla requires a restart, unsure about that).

Excellent work anyway, I like a guy who knows his stuff.

Comment by #
2003-08-19 15:07:50

I need to try this out;
just to see how it works
and to see IF it really works with my apple macintosh!

Comment by John #
2003-08-30 05:04:56

it works – great

Comment by Dreamszz #
2003-09-23 08:53:04

Excellent! Thanks! :) (y)

Comment by Ed Barker #
2004-08-09 07:29:04

Any way to moderate comments before they go live? I get quite a lot of offensive comments on my site



Comment by Phil Ringnalda #
2004-08-09 07:40:48