Skip to content

Instantly share code, notes, and snippets.

@hansek
Created December 12, 2012 15:03
Show Gist options
  • Save hansek/4268455 to your computer and use it in GitHub Desktop.
Save hansek/4268455 to your computer and use it in GitHub Desktop.
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