Force window.open() to create new tab in chrome

window.open must be called within a callback which is triggered by a user action (example onclick) for the page to open in a new tab instead of a window.

Example:

$("a.runReport").click(function(evt) {
    // open a popup within the click handler
    // this should open in a new tab
    var popup = window.open("about:blank", "myPopup");

    //do some ajax calls
    $.get("/run/the/report", function(result) {
        // now write to the popup
        popup.document.write(result.page_content);

        // or change the location
        // popup.location = 'someOtherPage.html';
    });
});

Leave a Comment