简体   繁体   中英

How to open multiple tabs with jquery $.each

I am trying to open X amount of tabs based off the rows selected in a table. When the ajax call returns, it hits the jquery foreach but only opens one tab for the 3 rows i select rather than a tab for each selection(3 tabs)... Any idea why this would be happen? All the data in the array is correct and url generation is working. It's just not opening a tab for each item in the array.

UPDATE: This works in IE 10 but not chrome fully..it opens only one for chrome. :( Thoughts on how to handle browsers?

    //FUNCTION
function viewContracts(selectedRows) {
    $.ajax({
        type: "POST",
        url: "/Home/SetContracts",
        data: { contracts: selectedRows.join() },
        async: false,
        success: function (data) {
            if (data == null) {
                alert('There was an error viewing the selected contracts.');
            }
            else {
                openContracts(selectedRows);
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert('There was an error viewing the selected contracts.');
            alert(thrownError);
        }
    });
}

//FUNCTION
function openContracts(selectedRows) {
    $(selectedRows).each(function (i, obj) {
        window.open('@Url.Action("ContractDetails", "Contract")' + '?contract=' + obj, '_blank');
    });
}

function openContracts(selectedRows) { $(selectedRows).each(function (i, obj) { window.open('@Url.Action("ContractDetails", "Contract")' + '?contract=' + obj, '_blank'); }); }

works in IE but chrome limits it to one tab

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