Confirm before redirecting

Show confirmation dialog before redirecting on click of `<a href=....`. Redirect only if user clicks on OK on the confirmation dialog. Ref: http://stackoverflow.com/questions/43272037/click-event-not-working

by Vivek Athalye

HTML

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<a href='https://example.com'>click here</a>

JavaScript

$(function(){
	$('a').click(function(e){
		if(!confirm('Do you want to redirect to "' + $(this).attr('href') + '" ?')) {
			e.preventDefault();
		}
	});
});