javascript - 带有 showModalDialog 的 Chrome 中的 window.opener.returnValue

标签 javascript return-value showmodaldialog

我正在尝试将 window.opener.returnValue 与 showModalDialog 结合使用。有许多引用资料可用于解决 window.returnValue 不起作用的技术。然而,它似乎在 Chrome 版本 23.0.1271.97 中不起作用。

如果我如下注释掉 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>

最佳答案

此外,window.returnValue 仅当模态对话框窗口父窗口(打开对话框) 都托管在同一个中时才有效服务器。如果不是,它将只返回 undefined

关于javascript - 带有 showModalDialog 的 Chrome 中的 window.opener.returnValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14441034/

相关文章:

javascript - Kendo UI 网格, Uncaught Error : Invalid Template

c# - 文本框接受 Javascript 中的以下值吗?

c# - 回发后使用 MVC C# 显示弹出确认消息

asp.net - 无法从模式对话框下载,window.showModalDialog

javascript - 如何过滤多个元素/元素

javascript - 找不到 AngularJS uibModal 依赖项

ios - 在方法之外获取值(value)

function - PowerShell哈希表返回值

java - 什么条件导致对象实例化返回null?

javascript - UI 对话框中 jQuery Load 函数中的相对路径