简体   繁体   中英

window.open external link opening in new tab

So I have a confirmation dialog box that opens when button is clicked, but window.open in javascript opens it in new tab. I tried lot of things like _self, _top but it doesn't work. Is there any way I can open this in same tab/page.

Here is the code:

<a href="http://www.google.com/" class="sample"></a>

JAVASCRIPT

 $('.sample').on("click", function (e)
    {
        var link = this;
        e.preventDefault();

        $( "#ConfirmDialog" ).dialog(
        {
            resizable: false,
            width: 300,
            buttons:
            {
                "Yes": function()
                {
                     window.open($(link).attr("href"));
                    $( this ).dialog( "close" );
                },
                Cancel: function()
                {
                    $( this ).dialog( "close" );
                }
            }
        });
    });

To change the current page's url, simply set window.location to the new url

$('.sample').on("click", function (e) {
    ....
            "Yes": function() {
                window.location = $(link).attr("href")     
            },
    ....
});

I have answered in the comments, but since this is what you are looking for, I'm adding it as an answer too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM