5

showModalDialog で window.opener.returnValue を使用しようとしています。window.returnValue が機能しないことを回避するために使用できる技術への参照が多数あります。ただし、バージョン 23.0.1271.97 の Chrome では機能しないようです。

次のように self.close 行をコメントアウトし、戻り値が設定される前後にアラートを配置すると、両方のアラートが「未定義」として表示されます。

呼び出し元 a1.html

<html>
<head>
    <base target="_self"/>
 <script>
  function fu()
  {
    window.returnValue = undefined;
    var result = window.showModalDialog("b1.html", window, "dialogHeight:650px; dialogWidth:900px;");
    if (result == undefined)
        result = window.returnValue;

    if (result != null && result != "undefined")
        text.value = result;
  }

 </script>
</head>
<body>
 <input type=button value="click me" onclick="return fu();">
 <input type=text id=text>
</body>
</html>

呼び出された b1.html:

<html>
<head>
<base target="_self"/>
<script>

  function fu()
  {
   var text = document.getElementById("text");
  if (window.opener)
  {
    alert(window.opener.returnValue);
    window.opener.returnValue = "your return value";
    alert(window.opener.returnValue);
  }
  text.value = window.opener.returnValue;
  //self.close();
  }


 </script>
</head>
<body>
 <input type=button value="close" onclick="return fu();">
 <input type=text id=text>
</body>
</html>
4

1 に答える 1