There's a target=_blank
link. A script in the linked page uses window.opener
, and this has worked for years, but now it's broken on iOS because window.opener
is null
. What can I do?
There are plenty of old (some very old) "window.opener is null" questions, and a Chromium bug that was closed in 2016. This seems to be a problem that es and goes with versions. It has a lot of variants, and no solution I can see that actually works. Key differences between my situation and some of the older questions:
- I don't have a cross-domain link.
- I see the null value in both Safari and Chrome, where others saw it in one but not the other.
- I have
target=_blank
, notwindow.open()
There's a target=_blank
link. A script in the linked page uses window.opener
, and this has worked for years, but now it's broken on iOS because window.opener
is null
. What can I do?
There are plenty of old (some very old) "window.opener is null" questions, and a Chromium bug that was closed in 2016. This seems to be a problem that es and goes with versions. It has a lot of variants, and no solution I can see that actually works. Key differences between my situation and some of the older questions:
- I don't have a cross-domain link.
- I see the null value in both Safari and Chrome, where others saw it in one but not the other.
- I have
target=_blank
, notwindow.open()
1 Answer
Reset to default 11After much searching, I found this:
https://bugs.webkit/show_bug.cgi?id=190481
Summary: Experiment: target=_blank on anchors should imply rel=noopener
and this:
https://webkit/blog/8475/release-notes-for-safari-technology-preview-68/
Changed target="_blank" on anchors to imply rel="noopener"
From the amount of plaints I received from iPhone users, I'm pretty sure this breaking change has appeared in the stable release of Safari, even though those links labeled "experimental" and "preview" are the only documentation I can find about it.
Mozilla has documented a similar feature for Firefox (https://developer.mozilla/en-US/docs/Mozilla/Firefox/Experimental_features#Security) but unlike Apple, their documentation clearly and correctly labels it as an experiment that is not enabled in the stable release.
To get the old behavior back, you need to add rel="opener"
to the <a>
element. MDN mentions this, not on the window.opener
page where I'm looking when window.opener
stops working, but on a page called Link types, which I was only able to find after I knew the answer already. They have it marked "experimental, do not use in production code" but I don't think I have a choice.