javascript 带有 showModalDialog 的 Chrome 中的 window.opener.returnValue
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14441034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
window.opener.returnValue in Chrome with showModalDialog
提问by Rob Sedgwick
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.
我正在尝试将 window.opener.returnValue 与 showModalDialog 一起使用。有很多关于可用于解决 window.returnValue 不起作用的技术的参考。然而,它似乎不适用于 Chrome 23.0.1271.97 版。
If I comment 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':
如果我如下注释掉 self.close 行,并在设置返回值之前和之后放置警报,则两个警报都显示为“未定义”:
The caller a1.html
调用者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:
所谓的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>
回答by SumRaj
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.
此外,仅当“模态对话框窗口”和“父窗口(打开对话框)”都托管在同一服务器中时,window.returnValue 才会起作用。如果不是,它将仅返回未定义。