它不起作用:noopener
在问题的情况下,该属性不会产生预期的效果——也就是说,对于从没有该href
属性的链接打开的窗口/选项卡。简单测试:
<!doctype html>
<title>simple noopener test</title>
<a onclick = "getUrl()"
rel = "noreferrer noopener">Case 1: click here to open a new tab that <b>will</b>
have access to the window object of this document (despite the'noopener')</a>
<p>
<a href="http://example.com"
rel = "noreferrer noopener">Case 2: click here to open a new tab that <b>will not</b>
have access to the window object of this document (because of the'noopener'</a>
<script>
var getUrl = function() {
window.open("http://example.com", '_blank');
}
</script>
In Case 1 in that example, if you check the window.opener
of the new tab/window that gets opened, you’ll see it’s non-null. But check the new window/tab in Case 2, and you’ll see it’s null.
Is there still any value on setting rel
value ?
No—for the case in the question, it seems there’s no value in setting noopener
, because it’s not going to prevent the new window/tab from access to the window
of the document that opened it.