我正在尝试将 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/