Normally when click anchor tag it redirects to some url which is given inside the "href" attribute. Is there is any possiblity here for confirmation. When we click anchor tag it shows confirmation "Are you sure want to continue" if we clicked "yes" it gets redirect to that url which is given inside "href". if we click "no" it remains in same page. Please share any ideas you might have.
Asked
Active
Viewed 3.6k times
15
-
1Check this http://jsfiddle.net/Nqzek/ – PiLHA Aug 06 '13 at 11:07
-
1Sure it is possible! What have you tried? – A. Wolff Aug 06 '13 at 11:07
-
Look at this: http://stackoverflow.com/questions/1289234/alerts-when-navigating-away-from-a-web-page – Hrishi Aug 06 '13 at 11:11
7 Answers
44
Try this
<a href="http://www.google.com" onclick="return confirm('Are you sure?')" >click here</a>

Satpal
- 132,252
- 13
- 159
- 168
5
You could do something like:
$('a').click(function(){
return confirm('Are you sure want to continue?');
});
Therefore if the user click's cancel you return false
and the link won't send you anywhere.

putvande
- 15,068
- 3
- 34
- 50
3
Try
<a href="www.anysite.com" onclick="return confirm('Are you sure?')">Any site</a>

Khadim Ali
- 2,548
- 3
- 33
- 61
3
You can do this by using below html link and jquery code. Don't forget to include Jquery library from http://jquery.com.
<a href="go.html?id=22" class="confirm">Go>></a>
<!-- Include jQuery - see http://jquery.com -->
<script type="text/javascript">
$('.confirm').on('click', function () {
return confirm('Are you sure want to continue?');
});
</script>

Laeeq
- 403
- 1
- 3
- 14
2
Yes
$('a').click(function(){
return confirm('do you want to proceed')
})

Arun P Johny
- 384,651
- 66
- 527
- 531
1
If you want a stylish box, jQuery has a Dialog Widget. This is the link to the widget's API: Dialog Widget - Open content in an interactive overlay.
I would use it as part of my confirm().

Aviv Shaked
- 762
- 3
- 8
-
Here is a nice tutorial on jQuery-style Dialog Boxes: http://savage.net.au/jQuery-tutorials/html/dialog.boxes.html – Aviv Shaked Aug 06 '13 at 11:17