簡體   English   中英

window.open在新選項卡中打開外部鏈接

[英]window.open external link opening in new tab

所以我有一個確認對話框,當單擊按鈕時會打開,但是javascript中的window.open在新選項卡中將其打開。 我嘗試了很多類似_self,_top的方法,但是它不起作用。 有什么辦法可以在同一標簽/頁面中打開它嗎?

這是代碼:

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

要更改當前頁面的網址,只需將window.location設置為新網址

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

我已經在評論中回答了,但是由於這是您要查找的內容,因此我也將其添加為答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM