I just learned about the rel="noopener"
attribute, which makes the opened windows unaware of their opener. I played with it a bit and got window.opener === null
all the time, until I found out that it's now the new default in all modern browsers.
Now, I'd like to actually read the window.opener
property to see how it works:
<!-- http://opener-from.test/ -->
<a href="http://opener-to.test/" target="_blank">no rel</a>
<a href="http://opener-to.test/" target="_blank" rel="opener">rel="opener"</a>
<a href="http://opener-to.test/" target="_blank" rel="noopener">rel="noopener"</a>
<!-- http://opener-to.test/ -->
<script>
console.log(window.opener);
</script>
The no rel
and rel="noopener"
links just make the destination get window.opener === null
. As for the rel="opener"
, it works great it Firefox and Safari, but in Google Chrome I'm getting the error:
Uncaught DOMException: Blocked a frame with origin "http://opener-to.test" from accessing a cross-origin frame.
I tested it in Chrome 91. How can I access the window.opener
in the context of target="_blank"
in Google Chrome?