1

Re:

Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

I am playing with a list of items I am sending from mysql via php o the browser.

In the browser I want to be able to say "Edit this record here".

I want to be able to use on desktop and on my phone.

The issue is that my phone allows me to navigate [give focus to] links, form buttons, form input fields etc but not say icon images. [Not a touch screen phone]

So if I don't use A HREF to pick up a focusable point for onclick events then what?

Thanks

Community
  • 1
  • 1
JJJ
  • 13
  • 2
  • Thanks all gave me great pointers in where it is all at these days [mobile, App, Page etc etc]. – JJJ Mar 20 '11 at 00:31

2 Answers2

0

The gist of the answers to that question isn't that you should never use anchors as sources of events you intend to handle in JavaScript, just that the anchors should be functional if JavaScript is disabled.

If your app won't work at all with JavaScript disabled, then I wouldn't worry about it and would just use the shortest thing, e.g. #. (Remember to cancel the default action when handling the event, so the page doesn't scroll back to the top.)

But if you can make your app somewhat functional when JavaScript is disabled, that would be even better. Whether that's feasible will depend on your app. For instance, barring other complexities, your "edit this record" link could, with JavaScript disabled, take you to a whole other page for editing the record — but if JavaScript is enabled, you intercept the click and do an in-place edit, that kind of thing.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Accessibility? If you want it to work in a screen reader (for the blind) support for browsers without javascript is required. – tvanfosson Mar 19 '11 at 21:40
  • @tvanfosson: I did say *"if you can make your app somewhat functional when JavaScript is disabled, that would be even better"* (I may have been adding it as you were reading.) There's a big difference between *apps* and *pages*, in my view. I believe strongly that *pages* should work when JavaScript is disabled. Apps are another matter entirely. :-) – T.J. Crowder Mar 19 '11 at 21:41
  • @TJ Crowder - yes, that edit appeared after my comment. I'd say apps are harder, but still important. Esp. if you work for the government (as I do) where it's the law. – tvanfosson Mar 19 '11 at 21:45
  • @tvanfosson: *(Well, the edit appeared after you landed on the page, not necessarily after your comment.)* Sure, agreed it can be important, depending on the audience. – T.J. Crowder Mar 19 '11 at 22:08
0

It would be best to use an image button for input:

<input type="image" src="someimage.gif" alt="Some Image" onclick="yourFunction()" />

Alternatively, you could also use this form of <a>:

<a href="javascript:yourFunction()">Some Link</a>
Brad
  • 159,648
  • 54
  • 349
  • 530