If you create a link with javascript handler, and href attribute doesn't matter for you, do not use # as the value of the attribute. This results in page scrolling to the top of the page in MSIE.
Instead, use value like javascript:// - this is safe and most browsers will ignore it. And this is what you want when you have an onclick handler, isn't it?
Update: I was pointed out, that if javascript click event was cancelled in onclick handler (like Event.stop(e) in prototype), you can safely put # to the href, because default click behaviour will be disabled in this case. This works, but I still prefer to put javascript:// to the link href - IMO this reveals intentions more explicit.
Apr 22, 2008
Subscribe to:
Post Comments (Atom)
1 comment:
Thank you, I was looking for putting javascript in the href, but this is even better!
Tested it on FF3, IE6&8 and Safari on Windows.
Thanks for sharing!
Post a Comment