第一个问题:刷新父窗口(没有传值操作)
父页面打开时一定要传window参数
openModalDialog("son.html",window,800,600);
子页面中刷新:
window.dialogArguments.location="parent.html";//parent.html是父页面的地址
实例:
parent.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> </TITLE>
<script type="text/javascript">
function openModalDialog(url,name,iWidth,iHeight)
{
window.showModalDialog(url,name,'edge: Raised; center: Yes; help: Yes; resizable: Yes; status: No;dialogHeight:'+iHeight+'px;dialogWidth:'+iWidth+'px');
}
function show(){
openModalDialog("son.html",window,800,600);
}
</script>
</HEAD>
<BODY>
<input type="button" value="open" onclick="show()">
</BODY>
</HTML>
son.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script type="text/javascript">
function aa(){
self.close();
window.dialogArguments.location="parent.html";
}
</script>
</HEAD>
<BODY>
test
<input type="button" value="close" onclick="aa()">
</BODY>
</HTML>
第二个问题:只传值不刷新
parent2.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script type="text/javascript">
function show(){
var params = new Array();
params[0] = "00000000000";
params[1] ="1111111111";
params[2]="22222222222";
var style = "dialogHeight:600px;dialogWidth:800px;status:no";
window.showModalDialog("son2.html",params, style);
}
</script>
</HEAD>
<BODY>
<input type="button" value="open" onclick="show()">
test
<input type="text">
</BODY>
</HTML>
son2.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
test
<br>
<label id="test"></label>
<br>
<div id="bb"></div>
<br>
<div id="cc"></div>
</BODY>
<script type="text/javascript">
var l_array=new Array();
l_array=window.dialogArguments;
var aa=l_array[0];
var bb=l_array[1];
var cc=l_array[2];
alert(aa);
alert(bb);
alert(cc);
document.getElementById("test").innerHTML = aa;
document.getElementById("bb").innerHTML = bb;
document.getElementById("cc").innerHTML = cc;
</script>
</HTML>
第三个问题:传值+刷新父窗口
father.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>传值+刷新</title>
<script type="text/javascript">
function show(){
var params = new Array();
params[0] = "00000000000";
params[1] ="1111111111";
params[2]="22222222222";
var style = "dialogHeight:600px;dialogWidth:800px;status:no";
var k=window.showModalDialog("son3.html",params, style);
if(k.type==""){ //传递回的type为空的时候才刷新页面。
alert("刷新我了");
location.reload();
}
}
</script>
</HEAD>
<BODY>
<input type="button" value="open" onclick="show()">
test
<input type="text">
</BODY>
</HTML>
child.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script type="text/javascript">
var s = new Object();
s.type=""; //设为空就可以刷新父窗口
window.returnValue=s;
var l_array=new Array();
l_array=window.dialogArguments;
var aa=l_array[0];
var bb=l_array[1];
var cc=l_array[2];
alert(aa);
alert(bb);
alert(cc);
function closeWindow(){
window.close();
}
function doNotRefresh(){
var s=new Object();
s.type="OK";//设置返回值,值随便写,不为空就可以。//这里返回不刷新父页面。
window.returnValue=s;
window.close();
}
</script>
</HEAD>
<BODY>
sdafsdfafasdf<br>
<input type="button" value="closeAndRefresh" onClick="closeWindow()" />
<input type="button" value="closeAndRefresh" onClick="doNotRefresh()" />
</BODY>
</HTML>