0

I've got a HTML link

<a href="http://jquery.com">Click</a>

I want to show a dialog box to ask if the user want to go to that website, if user clicked no, then does nothing, just close the dialog box; if clicked yes, then go to that link.

2 Answers 2

2

If you are okay with native alert boxes, then you can use confirm:

$(function() {
   $("a .confirm").click(function(e) {
      return confirm("Are you sure?");
   });
});

HTML:

<a href="http://jquery.com" class="confirm" />

This will add this functionality to all links with the confirm class. :-)

Sign up to request clarification or add additional context in comments.

1 Comment

This looks does not work here.. It went to the new link even if I cliecked no
0

This is just off the top of my head and not actually checked for accuracy but it's a close approximation of what you'll want to do.

$("a").click(function() {
    return (confirm("Are you sure you want to do this?"));
});

JS Confirm

jQuery Click

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.