简体   繁体   中英

javascript code is not opening in new tab

I've come across many forum posts regarding opening window as a new tab instead of new window but no use. When I click on a link/something.. at present it is opening in a new window but i want a tab instead of window.

Here is my sample code:

$(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.');
    }
}

I see this line in your code, which specifies width and height of the new window:

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

When you specify a width and a height the browser will always open in a new window instead of a new tab.

If you specify three parameters, your statement will always open a new window, not a new tab.

Your statement should probably read:

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

You can find more details here .

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