Debt Consolidation - Human body - Find jobs - Payday Loan - Customer services

PDA

View Full Version : avoiding "javascript:;" in status bar, when used as anchor href


Birmingham
Mar 12th 2008, 9:35 am
Hi, as far as I'm aware the best practice for setting onclick events with anchors is something like <a href="javascript:;" onclick="..."> ... but this produces an ugly "javascript:;" message in the status bar on most browsers.... so surely there's gotta be a better way?

is there no better way for accessibility?

nico_swd
Mar 12th 2008, 10:09 am
<a href="#" onclick="foo(); return false;">bar</a>

Birmingham
Mar 12th 2008, 10:30 am
that defeats the status bar effect, but i heard it's not good for accessibility due to it sending non-javascript users to "#" which is normally top of page. did i mis-hear?

nico_swd
Mar 12th 2008, 12:55 pm
Yep.

But you could drop the whole href attribute at all.

GreatMetro
Mar 13th 2008, 5:14 pm
You could also try:
<style>
.spanLink {
cursor: pointer;
}
</style>
<span class="spanLink" onclick="doSomething();">Link Text</span>

Logic Ali
Mar 13th 2008, 8:18 pm
You could also try:
<style>
.spanLink {
cursor: pointer;
}
</style>
<span class="spanLink" onclick="doSomething();">Link Text</span>If we're talking accessibility, how do you activate that with the keyboard?
It probably would have to be something like:
<span tabindex=1 class="spanLink" onkeypress="doSomething();" onclick="doSomething();">Link Text</span>
The best way to cater for non-JS users is either to provide an alternate URL.<a href='alternateURL.htm' onclick="doSomething();return false">Link</a> or less preferably to have script-generated links.

Here's another idea that I won't actually code.

All links with onclick handlers are given href and title attributes thus:
<a href="#REQUIRES_JAVASCRIPT" title="REQUIRES_JAVASCRIPT The proper title text" onclick='dosomething();return false'>

Then on page load, loop through all links stripping 'REQUIRES_JAVASCRIPT' from the href and title.

decepti0n
Mar 17th 2008, 1:22 pm
that defeats the status bar effect, but i heard it's not good for accessibility due to it sending non-javascript users to "#" which is normally top of page. did i mis-hear?

If you want the page to be accessible, the href would be to a normal, static page anyway


<a href="page.html" onclick="showpage(); return false;">Fork</a>