KBD

Keith Devens .com

Friday, July 4, 2008 Flag waving
... it's a lot faster to not do something than to do it. – Dan Sugalski
← Entry 1463Entry 1465 →

Daily link icon Friday, February 22, 2002

Entry 1464

I have to make a note about using "#" as the target for links when all you want out of the link is an anchor for your onClick event. I just linked to Dane Carlson, who has little arrows you can click on which pop up Radio's new comments feature.

That little arrow uses a "#" as the target of the link... why? You're supposed to use javascript:void(0) for these things. This has been known forever, but no one uses it... just like label tags have worked in IE forever, but no one uses them either...

I have to look though some old e-mail, but hopefully I'll post a justification for using javascript:void(0) here later. There are many reasons why this is better.

By the way, check out the JavaScript FAQ Knowledge Base from irt.org.

Ok, I found that old e-mail. Check out the void operator documentation from Netscape. Using some variant of javascript:void(0) is what they recommend: "You can use the void operator to specify an expression as a hypertext link. The expression is evaluated but is not loaded in place of the current document."

The main reason not to use the anchor "#" as a location is that it actually changes the URL you're browsing. It creates an extra location to go through in the history (so when you click back it looks like nothing happens), and most jarring is that it'll bump you up to the top of a web page.

Dane Carlson sent me an e-mail saying he knows about the problem, and that it's actually hardcoded that way into Radio so he can't help it. I didn't know that. Also, he referred me to this from Kottke.org: A short guide to doing JavaScript pop-up windows properly. I didn't even know about the best way to do it. Thanks Dane, Jason, and Milo Smiley

Dane also sent an e-mail to Dave Winer telling him about this. It'll be interesting to see if Dave acts on it.

← Entry 1463Entry 1465 →

Comments XML gif


Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

July 2008
SunMonTueWedThuFriSat
 12345
6789101112
13141516171819
20212223242526
2728293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 5 posts

Recent comments XML

new⇒Court rejects death penalty for raping children - Yahoo! News

Keith is not a person. I have this​on good authority. He's actually a​very,...

M. Bean: Jul 4, 2:05am

Girls, please don't get breast implants

> And no, you will not be receiving​a picture.

:-(...

Keith: Jul 2, 6:05am

Javascript clone function

This is a clever way to clone an​object if you are using YAHOO UI.​Same tec...

Antonio: Jul 1, 12:47pm

I hate Norton Antivirus

Oh just one other thing norton is​great at keeping people out of your​compu...

kevin.sands: Jul 1, 12:50am

Terminator 3 was awful

I think the biggest reason why T3​totally blew was because Edward​Furlong g...

76.167.172.64: Jun 29, 3:06am

Generated in about 0.115s.

(Used 8 db queries)

mobile phone