How to display a confirmation dialog when clicking an link?

I want this link to have a JavaScript dialog that asks the user “Are you sure? Y/N”.

<a href="https://stackoverflow.com/questions/10462839/delete.php?id=22">Link</a>

If the user clicks “Yes”, the link should load, if “No” nothing will happen.

I know how to do that in forms, using onclick running a function that returns true or false. But how do I do this with an <a> link?

9 Answers
9

Leave a Comment