簡體   English   中英

打開另一個窗口標簽時,如何防止當前窗口標簽頁重新加載?

[英]how to prevent current window tab page reload when another window tab is being opened?

我想知道如何在打開另一個窗口選項卡時防止當前窗口選項卡頁面重新加載。 實際上,我的頁面中有一個搜索字段。 填寫搜索字段並單擊搜索按鈕后,將打開一個新的窗口選項卡(在同一窗口中)。 這是javascript代碼的一部分,該代碼屬於單擊搜索按鈕之后打開新窗口選項卡的部分:

function affichegroupe(){

        var x = document.forms["formrecherche"]["recherche"].value;

         function ret(a){
                    var par = a;
                    var result;
                    $.ajax({        
                    type: "POST",
                    url: '{{asset('bundles/ikprojhome/recherche/moslem14.php')}}',
                    //dataType: 'JSON',
                    data:{par:par},
                    async: false,
                    success: function(data) {
                        result = data;
                        return;
                    }
                    });
                    return result;
        }
        var idgroupe = ret(x);

            //window.open(Pathmgroupe.replace('__REPLACEME__', idgroupe));
            var ch = Pathmgroupe1.replace('__REPLACEME__', idgroupe);
            var ch1 = ch.replace('__REPLACEME2__', visitorid);
            location.unload();
            window.open(ch1);
            return;
        }

請關注上面代碼的這一行: location.unload(); 問題在於,當打開新的窗口選項卡頁面時,當前的窗口選項卡頁面會重新加載! ..所以我的問題是:如果打開一個新的窗口標簽頁,是否可以防止當前窗口標簽重新加載? 我的代碼有什么問題?

確保您preventDefault提交:

document.forms["formrecherche"].addEventListener('submit', function(event) {
    event.preventDefault();
});

暫無
暫無

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

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