[JavaScript] window.open()でPOST

JavaScriptではPOSTの受信ができないらしい。
解決するためにPOSTを受信したいウィンドウを、
POST送信元のウィンドウの子にしてやることで送受信可能にした。

<html> 
  <script language="javascript"> 
    function test() { 
      var url = "http://hogehoge.html";
      var tagName = "TARGET";
      window.open("", tagName) ; 
      window.document.currentForm.action = url; 
      window.document.currentForm.target = tagName;
      window.document.currentForm.method = "POST";
      window.document.currentForm.submit();
    } 
  </script> 
  <form name="currentForm"> 
    <input type="hidden" name="curItem1" value="value1"> 
    <input type="hidden" name="curItem2" value="value2"> 
    <input type="button" value="go" onclick="test();"> 
  </form> 
</html>

受信側はwindow.openerを使うことで親ウィンドウにアクセスする。

  window.opener.document.currentForm.curItem1.value;
  window.opener.document.currentForm.curItem2.value;
最終更新:2010年12月08日 10:07
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。