Javascript function in link href="" - prevent from redirecting
I have a javascript function in HTML link HREF="" attribute. When I click on the link, it will rediect me on another page. What should I do to avoid the redirecting.
Hi,
To prevent from leaving the page after you click on the link, you have to use void(0); in href attribute and add javascript function into onClick event.
The solution should look like this:
<a href="javascript: void(0);" onClick="javascript: alert('Javascript function'); ">Link</a>
1 answer