簡體   English   中英

javascript代碼未在新標簽頁中打開

[英]javascript code is not opening in new tab

我遇到過許多關於將窗口作為新選項卡而不是新窗口打開的論壇帖子,但是沒有用。 當我單擊鏈接/某物時..目前它正在新窗口中打開,但我希望使用標簽而不是窗口。

這是我的示例代碼:

$(document).on('click', '#myTabs li', function (event) {
    if ($(event.target).attr('class') != 'closeIcon') {
        var temp_id = $(this).attr('id');
        selectedId = temp_id.substring(0, temp_id.length - 6);
        $('input:radio[id=all]').prop('checked', true);

        loadAll();
    }
});

function loadAll() {
    var clientForm = document.createElement("form");
    var target = "Map" + (windowCount++);
    clientForm.target = target;
    clientForm.method = "POST"; // or "post" if appropriate
    clientForm.action = "../Test.jsp";

    var idInput = document.createElement("input");
    idInput.type = "hidden";
    idInput.name = "id";
    idInput.value = id;
    clientForm.appendChild(idInput);
    document.body.appendChild(clientForm);

    var nameDisplay = document.createElement("input");
    nameDisplay.type = "hidden";
    nameDisplay.name = "idText";
    nameDisplay.value = idText;
    clientForm.appendChild(nameDisplay);
    document.body.appendChild(clientForm);

    var dateDisplay = document.createElement("input");
    dateDisplay.type = "hidden";
    dateDisplay.name = "dateText";
    dateDisplay.value = dateText;
    clientForm.appendChild(dateDisplay);
    document.body.appendChild(clientForm);

    map = window.open('', target, '_blank');
    map = window.open("", target, "status=0,title=0,height=600,width=800,scrollbars=1");

    if (map) {
        clientForm.submit();
    } else {
        alert('You must allow popups for this map to work.');
    }
}

我在您的代碼中看到了這一行,它指定了新窗口的寬度和高度:

map = window.open("", target, "status=0, title=0,height=600,width=800,scrollbars=1");

當您指定寬度和高度時,瀏覽器將始終在新窗口中打開,而不是新選項卡。

如果指定三個參數,則語句將始終打開一個新窗口,而不是一個新選項卡。

您的聲明可能應為:

window.open(<URL>, '_blank');

您可以在此處找到更多詳細信息。

暫無
暫無

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

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