How to create a script for open a tag href url in new window or tab only after clicking ok button in popup. there are multiple a tags with different urls.
$(document).ready(function() {
$("[target=_blank]").click(function() {
$(".popup").toggle();
});
$(".cancel").click(function() {
$(".popup").hide();
});
});
You can do it in following way:
http://jsfiddle.net/xdfoydy8/5/
$(document).ready(function() {
$("[target=_blank]").click(function(e) {
e.preventDefault();
$(".popup").show();
$("a.ok").data("hrefData", $(this).attr("href"));
});
$(".cancel").click(function() {
$(".popup").hide();
});
$("a.ok").click(function() {
var href = $(this).data("hrefData");
if ($.trim(href).length > 0) {
window.open(href, "_blank");
}
});
});
We are setting the clicked href
in ok link's $.data()
and retrieving it on click of ok click and taking user to clicked href