天天看點

javascript 父子視窗傳值示例代碼

javascript showModalDialog浼??間?FireFox??window.open ?跺??绐??d??肩ず渚?浠g??????绠???浠?缁?涓?涓??烘???ヨ??锛?

涓???window.open()??????澧?锛? Java1.0+/J1.0+/Nav2+/IE3+/Opera3+

浜????烘??璇?娉?锛?

window.open(pageURL,name,parameters)

?朵腑锛?

pageURL 涓哄??绐??h礬寰?

name 涓哄??绐??e?ユ??

parameters 涓虹???e?????????扮?ㄩ???峰????)

涓?????椤瑰????

?朵腑yes/no涔???浣跨??/0锛?pixel value涓哄?蜂????闆?鹼???浣?璞$???

????| ???艱????| 璇存??

alwaysLowered | yes/no | ??瀹?绐??i?????ㄦ????绐??d???

alwaysRaised | yes/no | ??瀹?绐??f??娴??ㄦ????绐??d?涓?

depended | yes/no | ???????剁???e???跺?抽??

directories | yes/no | Nav2??3????褰?????????瑙?

height | pixel value | 绐??i??搴?

hotkeys | yes/no | ?ㄦ病????????绐??d腑璁懼???ㄩ???虹????

innerHeight | pixel value | 绐??d腑??妗g????绱?楂?搴?

innerWidth | pixel value | 绐??d腑??妗g????绱?瀹藉害

location | yes/no | 浣?缃?????????瑙?

menubar | yes/no | ????????????瑙?

outerHeight | pixel value | 璁懼??绐???????瑁?楗拌竟妗?)????绱?楂?搴?

outerWidth | pixel value | 璁懼??绐???????瑁?楗拌竟妗?)????绱?瀹藉害

resizable | yes/no | 绐??eぇ灏???????璋???

screenX | pixel value | 绐??h?灞?骞?宸?竟??????绱??垮害

screenY | pixel value | 绐??h?灞?骞?涓?杈圭??????绱??垮害

scrollbars | yes/no | 绐??f????????婊??ㄦ??

titlebar | yes/no | 绐??i???????????瑙?

toolbar | yes/no | 绐??e伐?鋒????????瑙?

Width | pixel value | 绐??g????绱?瀹藉害

z-look | yes/no | 绐??h?婵?娲誨??????誕?ㄥ?跺??绐??d?涓?

window.showModalDialog浣跨?ㄦ????

?烘??浠?缁?锛?

showModalDialog() (IE 4+ ????)

showModelessDialog() (IE 5+ ????)

window.showModalDialog()?規??ㄦ?ュ??寤轟?涓??劇ずHTML??瀹圭??妯℃??瀵矽??妗???

window.showModelessDialog()?規??ㄦ?ュ??寤轟?涓??劇ずHTML??瀹圭????妯℃??瀵矽??妗???

浣跨?ㄦ?規?锛?

vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])

vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures])

???拌?存??锛?

sURL--

蹇??????幫?绫誨??锛?瀛?绗?覆???ㄦ?ユ??瀹?瀵矽??妗?瑕??劇ず????妗g??URL??

vArguments--

???????幫?绫誨??锛???浣????ㄦ?ュ??瀵矽??妗?浼??????般??浼????????扮被??涓???锛??????扮?绛???瀵矽??妗???杩?window.dialogArguments?ュ??寰?浼???杩??ョ?????般??

sFeatures--

???????幫?绫誨??锛?瀛?绗?覆???ㄦ?ユ??杩闆?矽??妗???澶?瑙?绛?淇℃??锛???浠ヤ嬌?ㄤ互涓???涓?涓?????涓?锛??ㄥ???封??;????寮???

1.dialogHeight :瀵矽??妗?楂?搴??涓?灏?浜?锛?锛?锛?px锛?锛╋譏锛?涓?dialogHeight ?? dialogWidth 榛?璁ょ????浣???em锛???锛╋譏锛?涓???px锛?涓烘?逛究?惰?锛??ㄥ??涔?modal?瑰???瀵矽??妗??訛???x????浣???

2.dialogWidth: 瀵矽??妗?瀹藉害??

3.dialogLeft: 绂誨?骞?宸???璺?绂彙??

4.dialogTop: 绂誨?骞?涓???璺?绂彙??

5.center: {yes | no | 1 | 0 }锛?绐??f?????涓?锛?榛?璁?es锛?浣?浠???浠ユ??瀹?楂?搴???瀹藉害??

6.help: {yes | no | 1 | 0 }锛??????劇ず甯??╂????锛?榛?璁?es??

7.resizable: {yes | no | 1 | 0 } 锛夥緝锛ワ?锛?锛斤???????琚??瑰??澶у???榛?璁?o??

8.status: {yes | no | 1 | 0 } 锛?E5+锛斤??????劇ず?舵??????榛?璁や負yes[ Modeless]??no[Modal]??

9.scroll:{ yes | no | 1 | 0 | on | off }锛?????瀵矽??妗??????劇ず婊??ㄦ?°??榛?璁や負yes??

涓??㈠??涓?灞??ф???ㄥ??TA涓???锛??ㄤ?????缃?椤典腑涓???涓?浣跨?ㄣ??

10.dialogHide:{ yes | no | 1 | 0 | on | off }锛??ㄦ???版???????伴?瑙??跺?矽??妗???????????榛?璁や負no??

11.edge:{ sunken | raised }锛?????瀵矽??妗???杈規??峰???榛?璁や負raised??

12.unadorned:{ yes | no | 1 | 0 | on | off }锛?榛?璁や負no??

???頒???锛?

1.瑕??沖?矽??妗?浼??????幫?????杩?vArguments?ヨ?琛?浼???????绫誨??涓????訛?瀵逛?瀛?绗?覆绫誨??锛???澶т負4096涓?瀛?绗???涔???浠ヤ???瀵矽薄锛?渚?濡?锛?

-------------------------------

parent.htm

澶??朵唬?? 浠g??濡?涓?:

涓??㈡??缃?涓?????????甯?涓?绡?娴?璇?浠g??锛?澶у?跺??浠ユ?璇?涓???

澶??朵唬?? 浠g??濡?涓?:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>涓婚〉??lt;/title>

</head>

<script type="text/javascript"><!--

//浼??扮?

function check(){

var mxh1 = new Array("mxh","net_lover","瀛?瀛?E绔?")

window.showModalDialog("test.html",mxh1,"unadorned:0;scroll:0;status:false;dialogWidth:380px;dialogHeight:200px");

}

//浼?瀵矽薄

function check1(){

var obj = new Object();

obj.name="zhangsan";

obj.age=2;

obj.sex="??;

window.showModalDialog("aaa.html",obj,"unadorned:0;scroll:0;status:false;dialogWidth:380px;dialogHeight:200px");

}

// --></script>

<body 慰nl慰ad="check1();">

</body>

</html>

test.html 婧?浠g??:

澶??朵唬?? 浠g??濡?涓?:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>?峰?涓婚〉?㈢????lt;/title>

</head>

<body>

script type="text/javascript"><!--

//浼??扮??瑰?

//var test = dialogArguments;

//alert(test[0]);

//alert(test[1]);

//alert(test[2]);

//浼?瀵矽薄?瑰?

var obj = dialogArguments;

alert(obj.name);

alert(obj.age);

alert(obj.sex);

// --></script>

<input type="text" />

</body>

</html>

showModalDialog 浼??煎???鋒??

showModalDialog浣跨?ㄤ?瀛?,?剁???e??瀛?绐??d?????瀛?绐??h?劇疆?剁???g????瀛?绐??e?抽?????跺??杩????煎?扮?剁????

farther.html

澶??朵唬?? 浠g??濡?涓?:

<!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 ></FONT>

<br>

浼????扮?剁???g????<input id="txt9" type="text" value="3333333333333" name="txt9"><br>

杩???????<input id="txt11" type="text" name="txt11"><br>

瀛?绐??h?劇疆????<input id="txt10" type="text" name="txt10"><br>

<input id="Button1" 慰nclick="openChild()" type="button" value="openChild" name="Button1">

</BODY>

</HTML>

child.html

澶??朵唬?? 浠g??濡?涓?:

<!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 ></FONT>

<br>

?剁???d????ョ????<input id="txt0" type="text" name="txt0"><br>

杈??ヨ?璁劇疆?剁???g????<input id="txt1" type="text" name="txt1"><input id="Button1" 慰nclick="setFather()" type="button" value="璁劇疆?剁???g???? name="Button1"><br>

杈??ヨ???????<input id="txt2" type="text" name="txt2"><input id="Button2" 慰nclick="retrunValue()" type="button" value="?抽????杩????? name="Button2">

<input id="Button3" 慰nclick="" type="button" value="?抽???鋒?扮?剁???? name="Button3">

<script language="javascript">

<!--

var k=window.dialogArguments;

//?峰??剁???d????ョ????

if(k!=null)

{

document.getElementById("txt0").value = k.document.getElementById("txt9").value;

}

//璁劇疆?剁???g????

function setFather()

{

k.document.getElementById("txt10").value = document.getElementById("txt1").value

}

//璁劇疆杩????扮?剁???g????

function retrunValue()

{

var s = document.getElementById("txt2").value;

window.returnValue=s;

window.close();

}

//-->

</script>

</BODY>

</HTML>

璇存??:

?變?showModalDialog缂?瀛?涓ラ??,涓??㈡???ㄥ??绐??e??娑?瀹㈡?風??缂?瀛???璁劇疆.涔???浠ュ?ㄦ???″?ㄧ????娑?缂?瀛?,????:

IT瀛??缃???涓?涓?绡???绔???

<meta http-equiv="Expires" CONTENT="0">

<meta http-equiv="Cache-Control" CONTENT="no-cache">

<meta http-equiv="Pragma" CONTENT="no-cache">

(浜?)涓??㈡???抽???鋒?扮?剁???g??渚?瀛?

farther.html

澶??朵唬?? 浠g??濡?涓?:

<!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>

浼????扮?剁???g????<input id="txt9" type="text" value="3333333333333" NAME="txt9"><br>

<input type="button" value="openChild" 慰nclick="openChild()" ID="Button1" NAME="Button1">

</BODY>

</HTML>

child.html

澶??朵唬?? 浠g??濡?涓?:

<!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 ></FONT>

<br>

?剁???d????ョ????<input id="txt0" type="text" name="txt0"><br>

<input id="Button1" 慰nclick="winClose(1)" type="button" value="?抽???鋒?扮?剁???? name="Button1">

<input id="Button2" 慰nclick="winClose(0)" type="button" value="?抽??涓??鋒?扮?剁???? name="Button2">

<script language="javascript">

<!--

var k=window.dialogArguments;

//?峰??剁???d????ョ????

if(k!=null)

{

document.getElementById("txt0").value = k.document.getElementById("txt9").value;

}

//?抽??绐??h????????鋒?扮??????

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">

涔???浠ュ?ㄦ???″?ㄧ????娑?缂?瀛?,????IT瀛??缃?涓?涓?绡???绔?

2.???剁???d?????杩闆??SP.NET涓?涔???浠ユ????aa.aspx?id=1???瑰?浼???.

3.涓??鋒?扮?剁???g??璇??ㄧ?剁???d腑?存?ヨ??蜂??ヨ?劇疆??浠?

<script>

window.showModalDialog("child.html",window,"dialogWidth:335px;status:no;dialogHeight:300px");

</script>

4.?ㄥ??绐??d腑?ヨ???浜ら〉?㈢??璇?瑕?????,杩??峰氨涓?浼???寮??扮???d?.

<head>

<base target="_self">

</HEAD>

繼續閱讀