javascript - window.opener.returnValue in Chrome with showModalDialog - Stack Overflow

I am trying to use window.opener.returnValue with showModalDialog. There are numerous references to a t

I am trying to use window.opener.returnValue with showModalDialog. There are numerous references to a technique which can be used to workaround window.returnValue not working. However it just doesn’t seem to work in Version 23.0.1271.97 of Chrome.

If I ment out the self.close line as follows, and put alerts in before and after the return value is set then both alerts show as ‘undefined’:

The caller 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>

The called 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>

I am trying to use window.opener.returnValue with showModalDialog. There are numerous references to a technique which can be used to workaround window.returnValue not working. However it just doesn’t seem to work in Version 23.0.1271.97 of Chrome.

If I ment out the self.close line as follows, and put alerts in before and after the return value is set then both alerts show as ‘undefined’:

The caller 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>

The called 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>
Share Improve this question asked Jan 21, 2013 at 14:44 Rob SedgwickRob Sedgwick 4,5346 gold badges59 silver badges91 bronze badges 3
  • I believe you should be setting the returnValue of the modal window, not the opener. Make sure you assign the return from window.showModalDialog to a variable, as this is where the returnValue goes. this question might be related to your issue. – jbabey Commented Jan 21, 2013 at 14:49
  • 1 the bug in Chrome (stackoverflow./questions/10213530/…) means you can't use returnValue of the modal window in this browser. That's why I am using window.opener instead. – Rob Sedgwick Commented Jan 21, 2013 at 14:59
  • Two years later and chrome still has the above bug. – SouthShoreAK Commented Jan 15, 2014 at 23:38
Add a ment  | 

1 Answer 1

Reset to default 0

Also window.returnValue will work only when both modal dialog window and parent window(which opened the dialog) are hosted in the same server. If not it will return undefined only.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745433465a4627500.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信