Using rel = "noopener" in window.open ()

Therefore, I know that when used, target="_blank"I can apply rel="noopenerin the tag a. But I'm trying to pass it as an argument window.open(), that is:

window.open('http://cats.com', '_blank', 'rel=noopener')

however, it does not work as I expected, since the object openerstill exists in the window after the user clicks on the link.

Is there something I am missing? Or can not be done as I intend?

I found some great articles, but as far as I can tell, they are not quite suitable for my use.

https://developer.mozilla.org/en-US/docs/Web/API/Window/open https://mathiasbynens.imtqy.com/rel-noopener/

Great importance.

+4
source share
3 answers

This worked for me:

const a = document.createElement("a")
a.href = args.url
a.target = "_blank"
a.rel = "noopener"
a.click()
+1
source

As far as I know, this cannot be achieved with arguments window.open(). There is, however, a way to get the behavior:

var newWindow = window.open();
newWindow.opener = null;
newWindow.location = 'http://some.url';
+1
source

There is no direct example in the doc , but it can be used like this, and it worked for me.

window.open('http://cats.com', '_blank', 'noopener,resizable,scrollbars')
+1
source

Source: https://habr.com/ru/post/1685412/


All Articles