Search code examples
javascriptwindow.openwindow.opener

Window.open with 'noopener' opens a new window instead of a new tab


I was using window.open('') with '_blank' as second parameter to open my link in new tab For eg. window.open('http://google.com', '_blank')

But, recently I added the third parameter 'noopener' so that window.opener becomes null in the new tab and the new tab does not have access to the parent tab/window. i.e. window.opener is null

window.open('http://google.com', '_blank', 'noopener')

So the above code solved the security problem, but instead of opening a new tab, a new window started opening which is not what I expected. My browser settings were same and no changes were made to it.

Is there anything I can do to make this code open new tab instead of new window ? I do not want to remove noopener as third parameter


Solution

  • Honestly i think your code is fine but you can try a different implementation:

    var yourWindow = window.open();
    yourWindow.opener = null;
    yourWindow.location = "http://someurl.here";
    yourWindow.target = "_blank";