第一個問題:刷新父窗口(沒有傳值操作) |
|
父頁面打開時一定要傳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> |
<mce: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); |
|
} |
// --></mce:script> |
</HEAD> |
|
<BODY> |
<input type= "button" value= "open" οnclick= "show()" > |
</BODY> |
</HTML> |
|
son.html |
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > |
<HTML> |
<HEAD> |
<TITLE> New Document </TITLE> |
<mce:script type= "text/javascript" ><!-- |
function aa(){ |
self.close(); |
window.dialogArguments.location= "parent.html" ; |
|
} |
// --></mce:script> |
</HEAD> |
|
<BODY> |
ssssssssssssssssssssssssssssssssss |
<input type= "button" value= "close" οnclick= "aa()" > |
</BODY> |
</HTML> |
|
================================= |
第二個問題:只傳值不刷新 |
parent2.html |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > |
<HTML> |
<HEAD> |
<mce: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); |
|
} |
// --></mce:script> |
</HEAD> |
|
<BODY> |
<input type= "button" value= "open" οnclick= "show()" > |
aaaaaaaaaaaaaaaaaanfddddaas |
<input type= "text" > |
</BODY> |
</HTML> |
|
son2.html |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > |
<HTML> |
<HEAD> |
<TITLE> New Document </TITLE> |
<mce: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); |
// --></mce:script> |
</HEAD> |
|
<BODY> |
ssssssssssssssssssssssssssssssssss |
</BODY> |
</HTML> |
第三個問題:傳值+刷新父窗口 |
|
father.html |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > |
<HTML> |
<HEAD> |
<TITLE>傳值+刷新父窗口 </TITLE> |
<mce:script language= "javascript" ><!-- |
|
function openson(){ |
var obj = new Object(); |
obj.name= "張三" ; |
obj.address= "中國北京市" ; |
var k =window.showModalDialog( "child.html" ,obj, "dialogWidth:800px;dialogHeight:600p;status:no;" ); |
if (k.type== "" ){ //傳遞迴的type爲空的時候才刷新頁面。 |
alert( "刷新了" ); //爲了看效果加的,實際運用中請注掉 |
location.reload(); |
} |
} |
// --></mce:script> |
</HEAD> |
|
<BODY> |
<input type= "button" value= "打開子窗口" οnclick= "openson()" > |
</BODY> |
</HTML> |
|
child.html |
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > |
<HTML> |
<HEAD> |
<TITLE></TITLE> |
<mce:script for = "window" event = "onload" ><!-- |
|
var s = new Object(); |
s.type= "" ; |
window.returnValue=s; |
|
var k=window.dialogArguments; |
alert(k.name); //使用傳遞過來的nanme "張三“; |
alert(k.address); //使用傳遞過來的address "中國北京市“; |
// --></mce:script> |
<mce:script type= "text/javascript" ><!-- |
|
|
|
function doRefresh(){ |
var s= new Object(); |
s.type= "" ; //設置返回值。//這裏返回刷新父頁面。 |
window.returnValue=s; |
window.close(); |
} |
|
function doNotRefresh(){ |
var s= new Object(); |
s.type= "OK" ; //設置返回值,值隨便寫,不爲空就可以。//這裏返回不刷新父頁面。 |
window.returnValue=s; |
window.close(); |
} |
// --></mce:script> |
</HEAD> |
<BODY> |
<input type= "button" value= "返回刷新" οnclick= "doRefresh()" > |
<input type= "button" value= "返回不刷新" οnclick= "doNotRefresh()" > |
</BODY> |
</HTML> |
|
第四個 傳值+刷新的實際應用 |
|
parent3.html |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > |
<HTML> |
<HEAD> |
<title>傳值+刷新</title> |
<mce: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(); |
} |
|
} |
// --></mce:script> |
</HEAD> |
|
<BODY> |
<input type= "button" value= "open" οnclick= "show()" > |
aaaaaaaaaaaaaaaaaanfddddaas |
<input type= "text" > |
</BODY> |
</HTML> |
|
son3.html |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > |
<HTML> |
<HEAD> |
<TITLE> New Document </TITLE> |
<mce: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(); |
} |
// --></mce:script> |
</HEAD> |
|
<BODY> |
sdafsdfafasdf<br> |
<input type= "button" value= "closeAndRefresh" onClick= "closeWindow()" /> |
<input type= "button" value= "closeAndRefresh" onClick= "doNotRefresh()" /> |
</BODY> |
</HTML> |