a标签target_blank为什么加rel=noopener

html yekong 1167℃

a页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <a href="b.html" target="_blank">da</a>
</body>
</html>

b页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <SCRIPT>window.opener.location.href ="https://www.wanjunshijie.com"</SCRIPT>
</body>
</html>

a.html中点击后打开新的tab页b页面,原tab页已经变成了其他页面。原因是使用target=_blank打开新的窗口时,赋予了新的窗口一些权限可以操作原tab页,其中window.location就是一个。

使用rel=noopener 防止window.opener被滥用

喜欢 (0)