javascript showModalDialog傳值與FireFox的window.open 父子窗口傳值示例第2/2頁(yè)
更新時(shí)間:2009年11月08日 22:36:15 作者:
javascript showModalDialog傳值與FireFox的window.open 父子窗口傳值示例代碼。
下面是網(wǎng)上的朋友發(fā)布一篇測(cè)試代碼,大家可以測(cè)試下。
復(fù)制代碼 代碼如下:
<!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>主頁(yè)面</title>
</head>
<script type="text/javascript"><!--
//傳數(shù)組
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");
}
//傳對(duì)象
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 onload="check1();">
</body>
</html>
test.html 源代碼:
復(fù)制代碼 代碼如下:
<!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>獲得主頁(yè)面的值</title>
</head>
<body>
script type="text/javascript"><!--
//傳數(shù)組方式
//var test = dialogArguments;
//alert(test[0]);
//alert(test[1]);
//alert(test[2]);
//傳對(duì)象方式
var obj = dialogArguments;
alert(obj.name);
alert(obj.age);
alert(obj.sex);
// --></script>
<input type="text" />
</body>
</html>
showModalDialog 傳值及刷新
showModalDialog使用例子,父窗口向子窗口傳遞值,子窗口設(shè)置父窗口的值,子窗口關(guān)閉的時(shí)候返回值到父窗口.
farther.html
復(fù)制代碼 代碼如下:
<!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>
子窗口設(shè)置的值:<input id="txt10" type="text" name="txt10"><br>
<input id="Button1" onclick="openChild()" type="button" value="openChild" name="Button1">
</BODY>
</HTML>
child.html
復(fù)制代碼 代碼如下:
<!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>
父窗口傳遞來(lái)的值:<input id="txt0" type="text" name="txt0"><br>
輸入要設(shè)置父窗口的值:<input id="txt1" type="text" name="txt1"><input id="Button1" onclick="setFather()" type="button" value="設(shè)置父窗口的值" name="Button1"><br>
輸入返回的值:<input id="txt2" type="text" name="txt2"><input id="Button2" onclick="retrunValue()" type="button" value="關(guān)閉切返回值" name="Button2">
<input id="Button3" onclick="" type="button" value="關(guān)閉刷新父窗口" name="Button3">
<script language="javascript">
<!--
var k=window.dialogArguments;
//獲得父窗口傳遞來(lái)的值
if(k!=null)
{
document.getElementById("txt0").value = k.document.getElementById("txt9").value;
}
//設(shè)置父窗口的值
function setFather()
{
k.document.getElementById("txt10").value = document.getElementById("txt1").value
}
//設(shè)置返回到父窗口的值
function retrunValue()
{
var s = document.getElementById("txt2").value;
window.returnValue=s;
window.close();
}
//-->
</script>
</BODY>
</HTML>
說(shuō)明:
由于showModalDialog緩存嚴(yán)重,下面是在子窗口取消客戶端緩存的設(shè)置.也可以在服務(wù)器端取消緩存,參考:
腳本之家的下一篇文章。
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
(二)下面是關(guān)閉刷新父窗口的例子
farther.html
復(fù)制代碼 代碼如下:
<!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
復(fù)制代碼 代碼如下:
<!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>
父窗口傳遞來(lái)的值:<input id="txt0" type="text" name="txt0"><br>
<input id="Button1" onclick="winClose(1)" type="button" value="關(guān)閉刷新父窗口" name="Button1">
<input id="Button2" onclick="winClose(0)" type="button" value="關(guān)閉不刷新父窗口" name="Button2">
<script language="javascript">
<!--
var k=window.dialogArguments;
//獲得父窗口傳遞來(lái)的值
if(k!=null)
{
document.getElementById("txt0").value = k.document.getElementById("txt9").value;
}
//關(guān)閉窗口返回是否刷新的參數(shù).
function winClose(isRefrash)
{
window.returnValue=isRefrash;
window.close();
}
//-->
</script>
</BODY>
</HTML>
說(shuō)明
1.下面是取消客戶端緩存的:
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
也可以在服務(wù)器端取消緩存,參考腳本之家下一篇文章
2.向父窗口傳遞闡述在ASP.NET中也可以是用aaa.aspx?id=1的方式傳遞.
3.不刷新父窗口的話在父窗口中直接這樣一來(lái)設(shè)置可以.
<script>
window.showModalDialog("child.html",window,"dialogWidth:335px;status:no;dialogHeight:300px");
</script>
4.在子窗口中若要提交頁(yè)面的話要加入:,這樣就不會(huì)打開新窗口了.
<head>
<base target="_self">
</HEAD>
您可能感興趣的文章:
- js操作模態(tài)窗口及父子窗口間相互傳值示例
- JavaScript實(shí)現(xiàn)彈出子窗口并傳值給父窗口
- JavaScript新窗口與子窗口傳值詳解
- js創(chuàng)建子窗口并且回傳值示例代碼
- JAVASCRIPT實(shí)現(xiàn)的WEB頁(yè)面跳轉(zhuǎn)以及頁(yè)面間傳值方法
- JS父頁(yè)面與子頁(yè)面相互傳值方法
- JS中Iframe之間傳值及子頁(yè)面與父頁(yè)面應(yīng)用
- JavaScript實(shí)現(xiàn)在頁(yè)面間傳值的方法
- javascript彈出頁(yè)面回傳值的方法
- JS簡(jiǎn)單實(shí)現(xiàn)父子窗口傳值功能示例【未使用iframe框架】
相關(guān)文章
30分鐘快速實(shí)現(xiàn)小程序語(yǔ)音識(shí)別功能
最近需要在小程序上實(shí)現(xiàn)語(yǔ)音識(shí)別,將需要用到的功能都總結(jié)下,供大家參考。語(yǔ)音識(shí)別用的是科大訊飛,文中給出了詳細(xì)的實(shí)現(xiàn)方法介紹,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11JS實(shí)現(xiàn)可移動(dòng)模態(tài)框
這篇文章主要為大家詳細(xì)介紹了JS實(shí)現(xiàn)可移動(dòng)模態(tài)框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07使用Turn.js實(shí)現(xiàn)翻書效果的完整步驟
最近項(xiàng)目經(jīng)理我個(gè)項(xiàng)目練練手,其項(xiàng)目需求是要實(shí)現(xiàn)翻書效果,下面這篇文章主要給大家介紹了關(guān)于使用Turn.js實(shí)現(xiàn)翻書效果的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-12-12JavaScript表單驗(yàn)證實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了JavaScript表單驗(yàn)證的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05JS變量中有var定義和無(wú)var定義的區(qū)別以及es6中l(wèi)et命令和const命令
這篇文章主要介紹了JS變量中有var定義和無(wú)var定義的區(qū)別以及es6中l(wèi)et命令和const命令,需要的朋友可以參考下2017-02-02微信小程序--onShareAppMessage分享參數(shù)用處(頁(yè)面分享)
本篇文章主要介紹了微信小程序的頁(yè)面分享onShareAppMessage分享參數(shù)用處的相關(guān)資料。具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-04-04JS實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)鏈接的幾種方式匯總
這篇文章主要介紹了JS實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)鏈接的幾種方式,簡(jiǎn)單總結(jié)了幾種頁(yè)面跳轉(zhuǎn)功能的實(shí)現(xiàn),有使用js跳轉(zhuǎn)頁(yè)面,返回上一次預(yù)覽界面及button按鈕添加事件跳轉(zhuǎn),本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2024-01-01ECMAScript6函數(shù)默認(rèn)參數(shù)
這篇文章主要介紹了ECMAScript6函數(shù)默認(rèn)參數(shù)的相關(guān)資料,需要的朋友可以參考下2015-06-06