获取在父窗口“联系”用 window.open 打开的子窗口

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
  </head>
  <body>
    <button onclick="clickHandler()">打开窗口</button>
    <script>
      function clickHandler() {
        const targetWindow = window.open("./sub.html");
        targetWindow.leitang = 1;
        alert(targetWindow.opener === window);
      }
    </script>
  </body>
</html>
原文地址:https://www.cnblogs.com/aisowe/p/15250129.html