Philadelphia Reflections

The musings of a physician who has served the community for over six decades

Related Topics

No topics are associated with this blog

HTML Anchor without an HREF?

Sometimes I want to execute a JavaScript function when a user clicks a link, but nothing else.

If I omit the href entirely, the cursor doesn't change and some browsers don't recognize the text as a link:

<a onclick="function();">

If I include the pound sign, which seems to be a very popular trick, I get sent to the top of the current page, which messes up both History and the backspace button; to say nothing of the fact that I don't want to jump to the top of the page:

<a href="#" onclick="function();">

Including the function in the href and omitting the onclick seems to be the answer to my specific problem:

<a href="javascript: function();">

Once again, my thanks to https://centricle.com/tools/html-entities/ for HTML encoding.

Originally published: Friday, April 04, 2008; most-recently modified: Monday, June 04, 2012

instead of one or the other use both, then it works in FF

this is my example;

a href="javascript:return openCenteredWindow('index/process.php');" onclick="return openCenteredWindow('index/process.php');"
Posted by: this is how   |   Oct 20, 2008 3:46 AM
"in the FF"?

Firefox? Works perfectly in mine, what version are you using? Do you have JavaScript enabled?
Posted by: g4   |   Jun 17, 2008 10:02 AM
Unfortunately in the FF it doesn't work
Posted by: Maxim   |   Jun 17, 2008 4:39 AM