4 回答
首先,您应该将<a>
url 保存在函数之外的全局变量中:
var linkBuffer;
$('a.external-link').click(function (e) {
//prevent browser to follow link
e.preventDefault();
//save link
linkBuffer = $(this).attr('href');
var popupid = "popuprel";
$('#' + popupid).fadeIn();
$('body').append('<div id="fade"></div>');
$('#fade').css({
'filter': 'alpha(opacity=80)'
}).fadeIn();
var popuptopmargin = ($('#' + popupid).height() + 10) / 2;
var popupleftmargin = ($('#' + popupid).width() + 10) / 2;
$('#' + popupid).css({
'margin-top': -popuptopmargin,
'margin-left': -popupleftmargin
});
});
因此,当您单击Yes弹出窗口时,只需更改窗口位置:
$('.link-continue').click(function () {
$('#fade , #popuprel').fadeOut();
document.location.href = linkBuffer;
});
更新:
这是给你的演示:http: //jsfiddle.net/zur4ik/fzn4Z/
请注意,当您在确认窗口中单击“是”时,JSFiddle 将不允许加载不同的链接(您可以在控制台中检查,当您单击时Yes),但它会在 JsFiddle 之外运行。
I would have $('.link-continue')
as an anchor element styled like button, which has link to the url proposed to navigate, so clicking on $('.link-continue')
take user to new page in same window. In case you want to open new window, preventDefault
in click listener of $('.link-continue')
, and use window.open
for same href
.
如果#popupre1
包含<a class = "link-continue">YES</a>
,您可以尝试像这样更改您的显示叠加功能
$('a.external-link').click(function() {
var popupid = "popuprel";
$('#' + popupid).fadeIn().find('.link-continue').attr('href',$(this).attr('href'));
$('body').append('<div id="fade"></div>');
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
var popuptopmargin = ($('#' + popupid).height() + 10) / 2;
var popupleftmargin = ($('#' + popupid).width() + 10) / 2;
$('#' + popupid).css({
'margin-top' : -popuptopmargin,
'margin-left' : -popupleftmargin
});
return false;
});
选项点击功能没有改变
代替
document.location.href = linkBuffer;
使用
window.open(linkBuffer,'_blank');
工作谢谢。
因此,继续按钮单击的代码变为:
$('.link-continue').click(function () {
$('#fade , #popuprel').fadeOut();
document.location.href = linkBuffer;
});