href = '#' ??

liunx

Guest
Hi guys,<br />
<br />
Quick question:<br />
<br />
Is it okay to use the '#' for the href value for a link? Especially if you use the onClick event handler to perform a function?<br />
<br />
Case in point:<br />
<br />
<a href=http://www.webdeveloper.com/forum/archive/index.php/"#" onClick="window.print()">Print</a><br />
<br />
Thanks!<!--content-->Might as well use something like this, so users with JavaScript don't get anything, rather than getting a link that doesn't work:<br />
<br />
<script type="text/javascript"><br />
document.write('<a href=http://www.webdeveloper.com/forum/archive/index.php/"#" onclick="window.print(); return false;">print</a>');<br />
</script><!--content-->So I guess using the '#' is fine?<br />
<br />
Thanks, pyro.<!--content-->for some browsers it's better to use:<br />
<br />
<a href=http://www.webdeveloper.com/forum/archive/index.php/"javasctipt:;" onClick="window.print()">Print</a><!--content-->Originally posted by olaf <br />
for some browsers it's better to useNo offense, but that notation is never better to use. It was always wrong, and still indeed is. The JavaScript pseudo-protocol has just about no place on the Web other than the occasinal bookmarklet. Ryan's method is far better, as non-JavaScript users won't get a link that does nothing.<!--content-->I remember that it was a problem in opera to use a "#"...<!--content-->... and why use a null-link if you don't use javascript event ? (or other methods)<!--content-->Originally posted by olaf <br />
... and why use a null-link if you don't use javascript event ? (or other methods) What's the onclick="window.print(); return false;" then?<br />
<br />
Anyway, as Fred said (sorta ;)), javascript: isn't a valid protocol for a URI, so it really doesn't have a place in the href attribute.<!--content-->...thanks for the input, guys.<!--content-->Hallo Ryan,<br />
<br />
you are right the print command is javascript but it was about <br />
<br />
"Ryan's method is far better, as non-JavaScript users won't get a link that does nothing."<br />
<br />
Maybe it's the time or my english (or both :) )<br />
<br />
I understand that this users (above) have nothing in a event or function...<!--content-->
 
Back
Top