(一)showModalDialog使用例子,父視窗向子視窗傳遞值,子視窗設定父視窗的值,子視窗關閉的時候傳回值到父視窗.
farther.html
---------------------------
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< HTML >
< HEAD >
< TITLE > New Document </ TITLE >
< META content ="EditPlus" name ="Generator" >
< META content ="" name ="Author" >
< META content ="" name ="Keywords" >
< META content ="" name ="Description" >
< script language ="javascript" >
<!--
function openChild(){
var k = window.showModalDialog( " child.html " ,window, " dialogWidth:335px;status:no;dialogHeight:300px " );
if (k != null )
document.getElementById( " txt11 " ).value = k;
}
// -->
</ script >
</ HEAD >
< BODY >
< FONT face ="宋體" ></ FONT >
< br >
傳遞到父視窗的值: < input id ="txt9" type ="text" value ="3333333333333" name ="txt9" >< br >
傳回的值: < input id ="txt11" type ="text" name ="txt11" >< br >
子視窗設定的值: < input id ="txt10" type ="text" name ="txt10" >< br >
< input id ="Button1" onclick ="openChild()" type ="button" value ="openChild" name ="Button1" >
</ BODY >
</ HTML >
child.html
---------------------------
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< HTML >
< HEAD >
< TITLE > New Document </ TITLE >
< META content ="EditPlus" name ="Generator" >
< META content ="" name ="Author" >
< META content ="" name ="Keywords" >
< META content ="" name ="Description" >
< meta http-equiv ="Expires" content ="0" >
< meta http-equiv ="Cache-Control" content ="no-cache" >
< meta http-equiv ="Pragma" content ="no-cache" >
</ HEAD >
< BODY >
< FONT face ="宋體" ></ FONT >
< br >
父視窗傳遞來的值: < input id ="txt0" type ="text" name ="txt0" >< br >
輸入要設定父視窗的值: < input id ="txt1" type ="text" name ="txt1" >< input id ="Button1" onclick ="setFather()" type ="button" value ="設定父視窗的值" name ="Button1" >< br >
輸入傳回的值: < input id ="txt2" type ="text" name ="txt2" >< input id ="Button2" onclick ="retrunValue()" type ="button" value ="關閉切傳回值" name ="Button2" >
< input id ="Button3" onclick ="" type ="button" value ="關閉重新整理父視窗" name ="Button3" >
< script language ="javascript" >
<!--
var k = window.dialogArguments;
// 獲得父視窗傳遞來的值
if (k != null )
{
document.getElementById( " txt0 " ).value = k.document.getElementById( " txt9 " ).value;
}
// 設定父視窗的值
function setFather()
{
k.document.getElementById( " txt10 " ).value = document.getElementById( " txt1 " ).value
}
// 設定傳回到父視窗的值
function retrunValue()
{
var s = document.getElementById( " txt2 " ).value;
window.returnValue = s;
window.close();
}
// -->
</ script >
</ BODY >
</ HTML >
----------------------------
說明:
由于showModalDialog緩存嚴重,下面是在子視窗取消用戶端緩存的設定.也可以在伺服器端取消緩存,參考:
http://adandelion.cnblogs.com/articles/252137.html
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
(二)下面是關閉重新整理父視窗的例子
farther.html
---------------------------
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< HTML >
< HEAD >
< TITLE > New Document </ TITLE >
< META NAME ="Generator" CONTENT ="EditPlus" >
< META NAME ="Author" CONTENT ="" >
< META NAME ="Keywords" CONTENT ="" >
< META NAME ="Description" CONTENT ="" >
< script language ="javascript" >
<!--
function openChild()
{
var k = window.showModalDialog( " child.html " ,window, " dialogWidth:335px;status:no;dialogHeight:300px " );
if (k == 1 ) // 判斷是否重新整理
{
alert('重新整理');
window.location.reload();
}
}
// -->
</ script >
</ HEAD >
< BODY >
< br >
傳遞到父視窗的值: < input id ="txt9" type ="text" value ="3333333333333" NAME ="txt9" >< br >
< input type ="button" value ="openChild" onclick ="openChild()" ID ="Button1" NAME ="Button1" >
</ BODY >
</ HTML >
child.html
----------------------
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< HTML >
< HEAD >
< TITLE > New Document </ TITLE >
< META content ="EditPlus" name ="Generator" >
< META content ="" name ="Author" >
< META content ="" name ="Keywords" >
< META content ="" name ="Description" >
< meta http-equiv ="Expires" content ="0" >
< meta http-equiv ="Cache-Control" content ="no-cache" >
< meta http-equiv ="Pragma" content ="no-cache" >
</ HEAD >
< BODY >
< FONT face ="宋體" ></ FONT >
< br >
父視窗傳遞來的值: < input id ="txt0" type ="text" name ="txt0" >< br >
< input id ="Button1" onclick ="winClose(1)" type ="button" value ="關閉重新整理父視窗" name ="Button1" >
< input id ="Button2" onclick ="winClose(0)" type ="button" value ="關閉不重新整理父視窗" name ="Button2" >
< script language ="javascript" >
<!--
var k = window.dialogArguments;
// 獲得父視窗傳遞來的值
if (k != null )
{
document.getElementById( " txt0 " ).value = k.document.getElementById( " txt9 " ).value;
}
// 關閉視窗傳回是否重新整理的參數.
function winClose(isRefrash)
{
window.returnValue = isRefrash;
window.close();
}
// -->
</ script >
</ BODY >
</ HTML >
--------------------------
說明
1.下面是取消用戶端緩存的:
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
也可以在伺服器端取消緩存,參考:
http://adandelion.cnblogs.com/articles/252137.html
2.向父視窗傳遞闡述在ASP.NET中也可以是用aaa.aspx?id=1的方式傳遞.
3.不重新整理父視窗的話在父視窗中直接這樣一來設定可以.
<script>
window.showModalDialog("child.html",window,"dialogWidth:335px;status:no;dialogHeight:300px");
</script>
4.在子視窗中若要送出頁面的話要加入:,這樣就不會打開新視窗了.
<head>
<base target="_self">
</HEAD>