子画面を開き親画面にデータを渡す

調査したいのは「サブウインドウでPOST後に、親ウインドウを更新して、サブウインドウを閉じる。」であるが、調査中。
(PHPを使用し、post、getにてデータ取得)

値だけは子画面から親画面にデータをセットすることはできたので記載する。
ソースは余計な箇所も記載した状態であるが、親ウィンドウからサブウィンドウにはデータをpostできているので残しておく。

親画面

<?php

echo('aaaa');
var_dump($_POST);
echo('bbb');
var_dump($_GET);

?>
<!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>

<form name="form1">
<input type="hidden" name="param1" value="hoge"/>
<input type="hidden" name="param2" value="hage"/>
<input type="button" value="送信" onclick="post_open();"/>
</form>
<input id="code1" type="text" /><br />

<div id="main">ボタン</div>
<script src="js/main.js"></script>
</body>
</html>

子画面

<?php

var_dump($_POST);

?>

<!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>
  <h1>サンプルaaa</h1>
  <form name="myform">
  <input type="button" onClick="child()" value="ボタン">
  <input type="text" name="moji">
  </form>
  <input name="searchCode" id="searchCode" type="text" />

  <script src="js/main.js"></script>
</body>
</html>

javascript

{

  
const mainId = document.getElementById('main');

// mainId.addEventListener('click',()=>{

//   alert('aaaa');
//   window.open('/sample.html','あああ','toolbar=no,scrollbars=no,width=800,height=650,left=10,top=50');


// });


function post_open() {
  window.open('', 'new_window','width=400,height=300,left=100,top=150');
  document.form1.action = 'SubScreen.php';
  document.form1.method = 'POST';
  document.form1.target = 'new_window';
  document.form1.submit();
}

function child(){
  var parantExistanceFlag = true;
  if ( !window.opener || !Object.keys(window.opener).length ) {
    window.alert('親画面が存在しません')
    parantExistanceFlag = false
  }

    //親画面に値を挿入
    if(parantExistanceFlag){
      window.opener.document.getElementById("code1").value
       = document.getElementById("searchCode").value
      }
       //ウィンドウを閉じる
      window.close();
}

}

参考サイト
JavaScriptで親画面に値を渡す小窓を作る方法 - Qiita