开发者

jQuery UI: button to open link in new window

I have the following code,

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;
        }
    }
});

which basically makes one of the buttons send the user somewhere. What I want it to do, is open the link in a new window or ta开发者_如何学Cb and then close the modal (as they will still have the original page open).

Any idea how I could resolve this?


Use window.open(targetUrl); instead of window.location.href, and add the line to close the dialog after that.

Here's an example fiddle (using some of the example dialog code from the jQuery UI docs, and I haven't included the CSS files, so it doesn't look like a dialog!)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜