Related Topics
No topics are associated with this blog
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
Posted by: this is how | Oct 20, 2008 3:46 AM |
Posted by: g4 | Jun 17, 2008 10:02 AM |
Posted by: Maxim | Jun 17, 2008 4:39 AM |
this is my example;
a href="javascript:return openCenteredWindow('index/process.php');" onclick="return openCenteredWindow('index/process.php');"