最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - window.opener is null (iOS 12.3.1 Safari and Chrome) - Stack Overflow

programmeradmin0浏览0评论

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, not window.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, not window.open()
Share Improve this question asked Jul 16, 2019 at 15:27 user2404501user2404501
Add a ment  | 

1 Answer 1

Reset to default 11

After 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.

发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>