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.
posted on 16.05.2020 at 17:56
0pnshow more
StorStor
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>
posted on 17.05.2020 at 10:57
0pnshow more
TimTim
share on facebookshare on twitter
2020 AnswerTabsTermsContact us
This site uses cookies to improve your experience, for analytics and ads. By continuing to browse this site you agree to our use of cookies.