新しいWindowを開いてPOSTを送信する

  • ダイアログ的な使い方をしたいが、POSTしか使えない場合の方法
// 親画面のformは↓こんな感じになっているとする。
// <form name="parentForm" action="http://xxxx" method="post">...</form>
function openChild(id, mode) {
  window.open("","window_name","width=300,height=200,menubar=no,toolbar=no");
  // ターゲットを指定。window.open()の第2引数と一致していること。
  document.formParent.target = "window_name";
  // パラメータなど
  document.formParent.id.value = id;
  document.formParent.mode.value = mode;
  // サブミット
  document.formParent.submit();
}

しかしこれだと、一回実行すると、それ以降どのボタンを押してもダイアログが
開くようになるので、この処理の前後で、ターゲット(必要ならば他のパラメータも)を
一旦保存して戻す処理が必要になる。

function openChild(id, mode) {
  // 保存
  var org_target = document.formParent.target;
  // window.openからsubmitまでの処理
  // 戻す
  document.formParent.target = org_target;
}

実はこれでずいぶんはまった。。。