开发者

jQuery UI: button to open link in new window

开发者 https://www.devze.com 2023-03-25 19:52 出处:网络
I have the following code, var targetUrl = $(this).attr(\"href\"); $(\"#leaving-dialog\").dialog({ buttons: {

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

精彩评论

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