Created
December 12, 2012 15:03
-
-
Save hansek/4268455 to your computer and use it in GitHub Desktop.
jQuery UI confirm dialog for link, reflects target="_blank"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
THIRD_PARTY_LINK_TITLE = 'Dialog title'; | |
THIRD_PARTY_LINK_TEXT = 'Dialog text ...'; | |
// JS 3rd party link confirm dialog | |
$('.3rd-party-link').on('click', function() { | |
var anchor = this; | |
$('<div></div>') | |
.appendTo('body') | |
.html('<div>'+ THIRD_PARTY_LINK_TEXT +'</div>') | |
.dialog({ | |
modal: true, | |
title: THIRD_PARTY_LINK_TITLE, | |
zIndex: 10000, | |
autoOpen: true, | |
width: '500px', | |
resizable: false, | |
buttons: { | |
"Cancel": function() { | |
$( this ).dialog( "close" ); | |
}, | |
"OK": function() { | |
$( this ).dialog( "close" ); | |
if ($(anchor).attr('target') === 'undefined' || ($(anchor).attr('target') !== 'undefined' && $(anchor).attr('target') !== '_blank')) { | |
window.location.href = $(anchor).attr('href'); | |
} | |
else { | |
window.open($(anchor).attr('href'), ''); | |
} | |
} | |
}, | |
close: function (event, ui) { | |
$(this).remove(); | |
} | |
} | |
); | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment