[thelist] href=# versus href=JavaScript.....

James Aylard jaylard at encompass.net
Thu Feb 22 00:53:58 CST 2001


Anthony,

> What I'm not saying is that anchors are bad. I just think that if the HREF
> is not designed to go to another page or anchor on the same page - you
> shouldn't be using href=# as a place holder for "go no where". I have come
> to the conclusion that its just sloppy coding.

	Probably most of the time it is. I am of the school that, if the link is
going to open a new window using javascript, the function call should be in
the onclick event handler, and the url should be placed as the value of the
href attribute. This allows the link to work in non-JS-equipped browsers, as
well. Obviously, though, sometimes the href is only being used to call a
function -- such as window.close() -- and there isn't an href to be used. In
IE 4+, of course, you can put an onclick on just about anything, so you can
avoid the use of the anchor element and the href attribute altogether.
Mostly true with Netscape 6, too.
	One thing I've seen, but have seen little explanation of, is to use #null
as the href in cases where an anchor must be used. Heidi Housten, who now
writes for MSDN, was the first one I saw do that on another list
(http://microsoft.ease.lsoft.com/scripts/wa-msn.exe?A2=ind9901D&L=IE-HTML&P=
R7619). The alternative is to place the javascript function call in the
href, but this can give you funky results in older or non-JS-enabled
browsers, if I recall. The #null approach avoids that.

James Aylard





More information about the thelist mailing list