Skip to content

Instantly share code, notes, and snippets.

@hansek

hansek/gist:4268455

Created Dec 12, 2012
Embed
What would you like to do?
jQuery UI confirm dialog for link, reflects target="_blank"
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