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
Another approach that will solve this in one line is to access the opener property directly and set it to null to make use of the fact that window.open()
returns a Window
object. This will work across all browsers to open a new tab with a null window.opener
.
window.open(url, '_blank').opener = null;
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";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With