If the user clicks a link, I want to call a Javascript function if JS is enabled, or go to a URL if it’s disabled. How to solve this? I’ve tried
<a href="/url?img=2" onclick="changeImage(2); return false;">
but it doesn’t seem to work.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try returning
falsefrom your JavaScript function. This causes the browser to halt and not follow the link after your function is finished.I’m assuming that when you click the link now, you are just taken to the url and the JavaScript does not seem to work. Is that correct?