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

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


You can try this:

<a href="javascript:openWindow();">open a new tab please</a><script>    function openWindow(){        var w = window.open("about:blank");        w.document.write("heheh new page opened");    }</script>


Is very easy, in order to force Chrome to open in a new tab, use the onmouseup event

onmouseup="switchMenu(event);"