我有以下代码,
var targetUrl = $(this).attr("href");
$("#leaving-dialog").dialog({
buttons: {
"No, I want to stay here": function () {
$(this).dialog("close");
},
"Yes, that's okay": function () {
window.location.href = targetUrl;
}
}
});
这基本上使其中一个按钮将用户发送到某个地方。我想要它做的是在新窗口或选项卡中打开链接,然后关闭模式(因为它们仍然会打开原始页面)。
知道如何解决这个问题吗?
最佳答案
使用 window.open(targetUrl);
而不是 window.location.href
,然后添加行来关闭
对话框.
这是一个example fiddle (使用 jQuery UI 文档中的一些示例 dialog
代码,并且我没有包含 CSS 文件,因此它看起来不像对话框!)
关于javascript - jQuery 用户界面 : button to open link in new window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6911626/