This is either perfectly simple or quite impossible, but no amount of searching has found me the answer. For reasons too complex to get into, I want to run a JavaScript function when a user clicks on a hyperlink. But I need the link to work as normal too. <a href="http://example.com/" onclick="javascript:myFunction();"> Code (markup): In the above example, I want myFunction to execute AND I want the user to wind up at example.com. Is it possible? How would I do it? Currently, it doesn't execute the funtion. If I add a "return false" to the onclick, it executes the function but doesn't open the link. (if you need to know what I'm trying to achieve -- the URL in my real code references an external application in much the same way as a mailto: would open Outlook. When the user clicks the link, I want the link to open the external application, then run the myFunction (which dynamically rewrites that URL for when it is clicked next)) Any help would be greatly appreciated. I'm quite new to JavaScript.
Could you post the code of myFunction() ? And also, there's no need for the "javascript:" in the onclick attribute as the browser expects a script there.
Thanks Nico_SWD. I've removed the "javascript:" bit, and will remember that in future. I'm not sure what the point of posting the code for myFunction would be. It works fine when it executes. My problem is that it doesn't execute.