javascript showModalDialog傳值與FireFox的window.open 父子窗口傳值示例第1/2頁
更新時(shí)間:2009年11月08日 22:36:15 作者:
javascript showModalDialog傳值與FireFox的window.open 父子窗口傳值示例代碼。
先簡單介紹一下基本知識(shí):
一、window.open()支持環(huán)境: Java1.0+/J1.0+/Nav2+/IE3+/Opera3+
二、基本語法:
window.open(pageURL,name,parameters)
其中:
pageURL 為子窗口路徑
name 為子窗口句柄
parameters 為窗口參數(shù)(各參數(shù)用逗號(hào)分隔)
三、各項(xiàng)參數(shù)
其中yes/no也可使用1/0;pixel value為具體的數(shù)值,單位象素。
參數(shù) | 取值范圍 | 說明
alwaysLowered | yes/no | 指定窗口隱藏在所有窗口之后
alwaysRaised | yes/no | 指定窗口懸浮在所有窗口之上
depended | yes/no | 是否和父窗口同時(shí)關(guān)閉
directories | yes/no | Nav2和3的目錄欄是否可見
height | pixel value | 窗口高度
hotkeys | yes/no | 在沒菜單欄的窗口中設(shè)安全退出熱鍵
innerHeight | pixel value | 窗口中文檔的像素高度
innerWidth | pixel value | 窗口中文檔的像素寬度
location | yes/no | 位置欄是否可見
menubar | yes/no | 菜單欄是否可見
outerHeight | pixel value | 設(shè)定窗口(包括裝飾邊框)的像素高度
outerWidth | pixel value | 設(shè)定窗口(包括裝飾邊框)的像素寬度
resizable | yes/no | 窗口大小是否可調(diào)整
screenX | pixel value | 窗口距屏幕左邊界的像素長度
screenY | pixel value | 窗口距屏幕上邊界的像素長度
scrollbars | yes/no | 窗口是否可有滾動(dòng)欄
titlebar | yes/no | 窗口題目欄是否可見
toolbar | yes/no | 窗口工具欄是否可見
Width | pixel value | 窗口的像素寬度
z-look | yes/no | 窗口被激活后是否浮在其它窗口之上
window.showModalDialog使用手冊
基本介紹:
showModalDialog() (IE 4+ 支持)
showModelessDialog() (IE 5+ 支持)
window.showModalDialog()方法用來創(chuàng)建一個(gè)顯示HTML內(nèi)容的模態(tài)對話框。
window.showModelessDialog()方法用來創(chuàng)建一個(gè)顯示HTML內(nèi)容的非模態(tài)對話框。
使用方法:
vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])
vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures])
參數(shù)說明:
sURL--
必選參數(shù),類型:字符串。用來指定對話框要顯示的文檔的URL。
vArguments--
可選參數(shù),類型:變體。用來向?qū)υ捒騻鬟f參數(shù)。傳遞的參數(shù)類型不限,包括數(shù)組等。對話框通過window.dialogArguments來取得傳遞進(jìn)來的參數(shù)。
sFeatures--
可選參數(shù),類型:字符串。用來描述對話框的外觀等信息,可以使用以下的一個(gè)或幾個(gè),用分號(hào)“;”隔開。
1.dialogHeight :對話框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默認(rèn)的單位是em,而IE5中是px,為方便其見,在定義modal方式的對話框時(shí),用px做單位。
2.dialogWidth: 對話框?qū)挾取?
3.dialogLeft: 離屏幕左的距離。
4.dialogTop: 離屏幕上的距離。
5.center: {yes | no | 1 | 0 }:窗口是否居中,默認(rèn)yes,但仍可以指定高度和寬度。
6.help: {yes | no | 1 | 0 }:是否顯示幫助按鈕,默認(rèn)yes。
7.resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改變大小。默認(rèn)no。
8.status: {yes | no | 1 | 0 } [IE5+]:是否顯示狀態(tài)欄。默認(rèn)為yes[ Modeless]或no[Modal]。
9.scroll:{ yes | no | 1 | 0 | on | off }:指明對話框是否顯示滾動(dòng)條。默認(rèn)為yes。
下面幾個(gè)屬性是用在HTA中的,在一般的網(wǎng)頁中一般不使用。
10.dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印預(yù)覽時(shí)對話框是否隱藏。默認(rèn)為no。
11.edge:{ sunken | raised }:指明對話框的邊框樣式。默認(rèn)為raised。
12.unadorned:{ yes | no | 1 | 0 | on | off }:默認(rèn)為no。
參數(shù)傳遞:
1.要想對話框傳遞參數(shù),是通過vArguments來進(jìn)行傳遞的。類型不限制,對于字符串類型,最大為4096個(gè)字符。也可以傳遞對象,例如:
-------------------------------
parent.htm
<script type="text/javascript">
var obj = new Object();
obj.name="51js";
window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");
</script>
modal.htm
<script type="text/javascript">
var obj = window.dialogArguments
alert("您傳遞的參數(shù)為:" + obj.name)
</script>
-------------------------------
2.可以通過window.returnValue向打開對話框的窗口返回信息,當(dāng)然也可以是對象。例如:
------------------------------
parent.htm
< type="text/java">
str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");
alert(str);
</script>
modal.htm
<script type="text/javascript">
window.returnValue="http://www.dhdzp.com";
</script>
在IE中,我們可以使用showModalDialog來傳值。
語法如下:
vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])
但是.在Firefox中卻沒有showModalDialog方法,不過我們可以用window.open()
語法如下:
oNewWindow = window.open( [sURL] [, sName] [, sFeatures] [, bReplace])
只是,在Firefox下,window.open的參數(shù)中,sFeature多了一些功能設(shè)定,而在FireFox下要讓開啟的視窗跟IE的showModalDialog一樣的話,只要在sFeatures中加個(gè)modal=yes就可以了。
下面用一個(gè)示例來說明其用法。
功能說明:從子窗口中輸入顏色種類提交到父窗口,并添加選項(xiàng)到下拉列表。
a.html
<!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>a.html文檔</title>
<script language="javascript">
function openstr()
{
ReturnValue=window.showModalDialog("b.html",window,"dialogWidth=510px;dialogHeight=150px;status=no");
if(ReturnValue && ReturnValue!="")
{
oOption = document.createElement('OPTION');
oOption.text=ReturnValue;
oOption.value=ReturnValue;
document.all.txtselect.add(oOption);
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="txtselect" id="txtselect">
</select>
</label>
<label>
<input type="button" name="Submit" value="打開子窗口" onclick="openstr()" />
</label>
</form>
</body>
</html>
b.html
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>b.html文檔</title>
<script language="javascript">
function ClickOk()
{
var t=document.Edit;
var url=t.color.value;
if(url==null||url=="填寫顏色") return(false);
window.returnValue=url;
window.close();
}
</script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="2" align="center" width="300">
<form name="Edit" id="Edit">
<tr>
<td width="30" align="right" height="30">color:</td>
<td height="30"><input type="text" name="color" value="填寫顏色" /></td>
<td width="56" align="center" height="30"><input " type="button" name="bntOk" value="確認(rèn)" onclick="ClickOk();" /> </td>
</tr>
</form>
</table>
</body>
</html>
修改為兼容IE和FireFoxr的代碼如下:
[code]
<!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>a.html文檔</title>
<script type="text/javascript">
function openstr()
{
window.open("b.html","","modal=yes,width=500,height=500,resizable=no,scrollbars=no");
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="txtselect" id="txtselect">
</select>
</label>
<label>
<input type="button" name="Submit" value="打開子窗口" onclick="openstr()" />
</label>
</form>
</body>
</html>
b.html
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>b.html文檔</title>
<script type="text/javascript">
function ClickOk()
{
var t=document.Edit;
var color=t.color.value;
if(color==null||color=="填寫顏色") return(false);
var oOption = window.opener.document.createElement('OPTION');
oOption.text=url;
oOption.value=url;
//檢查瀏覽器類型
var bname = navigator.appName;
if (bname.search(/netscape/i) == 0)
{
window.opener.document.getElementById("txtselect").appendChild(oOption);
}
else if (bname.search(/microsoft/i) == 0)
{
window.opener.document.all.txtselect.add(oOption);
}
else
{
}
window.close();
}
</script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="2" align="center" width="300">
<form name="Edit" id="Edit">
<tr>
<td width="30" align="right" height="30">color:</td>
<td height="30"><input type="text" name="color" value="填寫顏色" /></td>
<td width="56" align="center" height="30"><input " type="button" name="bntOk" value="確認(rèn)" onclick="ClickOk();" /> </td>
</tr>
</form>
</table>
</body>
</html>
一、window.open()支持環(huán)境: Java1.0+/J1.0+/Nav2+/IE3+/Opera3+
二、基本語法:
window.open(pageURL,name,parameters)
其中:
pageURL 為子窗口路徑
name 為子窗口句柄
parameters 為窗口參數(shù)(各參數(shù)用逗號(hào)分隔)
三、各項(xiàng)參數(shù)
其中yes/no也可使用1/0;pixel value為具體的數(shù)值,單位象素。
參數(shù) | 取值范圍 | 說明
alwaysLowered | yes/no | 指定窗口隱藏在所有窗口之后
alwaysRaised | yes/no | 指定窗口懸浮在所有窗口之上
depended | yes/no | 是否和父窗口同時(shí)關(guān)閉
directories | yes/no | Nav2和3的目錄欄是否可見
height | pixel value | 窗口高度
hotkeys | yes/no | 在沒菜單欄的窗口中設(shè)安全退出熱鍵
innerHeight | pixel value | 窗口中文檔的像素高度
innerWidth | pixel value | 窗口中文檔的像素寬度
location | yes/no | 位置欄是否可見
menubar | yes/no | 菜單欄是否可見
outerHeight | pixel value | 設(shè)定窗口(包括裝飾邊框)的像素高度
outerWidth | pixel value | 設(shè)定窗口(包括裝飾邊框)的像素寬度
resizable | yes/no | 窗口大小是否可調(diào)整
screenX | pixel value | 窗口距屏幕左邊界的像素長度
screenY | pixel value | 窗口距屏幕上邊界的像素長度
scrollbars | yes/no | 窗口是否可有滾動(dòng)欄
titlebar | yes/no | 窗口題目欄是否可見
toolbar | yes/no | 窗口工具欄是否可見
Width | pixel value | 窗口的像素寬度
z-look | yes/no | 窗口被激活后是否浮在其它窗口之上
window.showModalDialog使用手冊
基本介紹:
showModalDialog() (IE 4+ 支持)
showModelessDialog() (IE 5+ 支持)
window.showModalDialog()方法用來創(chuàng)建一個(gè)顯示HTML內(nèi)容的模態(tài)對話框。
window.showModelessDialog()方法用來創(chuàng)建一個(gè)顯示HTML內(nèi)容的非模態(tài)對話框。
使用方法:
vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])
vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures])
參數(shù)說明:
sURL--
必選參數(shù),類型:字符串。用來指定對話框要顯示的文檔的URL。
vArguments--
可選參數(shù),類型:變體。用來向?qū)υ捒騻鬟f參數(shù)。傳遞的參數(shù)類型不限,包括數(shù)組等。對話框通過window.dialogArguments來取得傳遞進(jìn)來的參數(shù)。
sFeatures--
可選參數(shù),類型:字符串。用來描述對話框的外觀等信息,可以使用以下的一個(gè)或幾個(gè),用分號(hào)“;”隔開。
1.dialogHeight :對話框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默認(rèn)的單位是em,而IE5中是px,為方便其見,在定義modal方式的對話框時(shí),用px做單位。
2.dialogWidth: 對話框?qū)挾取?
3.dialogLeft: 離屏幕左的距離。
4.dialogTop: 離屏幕上的距離。
5.center: {yes | no | 1 | 0 }:窗口是否居中,默認(rèn)yes,但仍可以指定高度和寬度。
6.help: {yes | no | 1 | 0 }:是否顯示幫助按鈕,默認(rèn)yes。
7.resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改變大小。默認(rèn)no。
8.status: {yes | no | 1 | 0 } [IE5+]:是否顯示狀態(tài)欄。默認(rèn)為yes[ Modeless]或no[Modal]。
9.scroll:{ yes | no | 1 | 0 | on | off }:指明對話框是否顯示滾動(dòng)條。默認(rèn)為yes。
下面幾個(gè)屬性是用在HTA中的,在一般的網(wǎng)頁中一般不使用。
10.dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印預(yù)覽時(shí)對話框是否隱藏。默認(rèn)為no。
11.edge:{ sunken | raised }:指明對話框的邊框樣式。默認(rèn)為raised。
12.unadorned:{ yes | no | 1 | 0 | on | off }:默認(rèn)為no。
參數(shù)傳遞:
1.要想對話框傳遞參數(shù),是通過vArguments來進(jìn)行傳遞的。類型不限制,對于字符串類型,最大為4096個(gè)字符。也可以傳遞對象,例如:
-------------------------------
parent.htm
復(fù)制代碼 代碼如下:
<script type="text/javascript">
var obj = new Object();
obj.name="51js";
window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");
</script>
modal.htm
復(fù)制代碼 代碼如下:
<script type="text/javascript">
var obj = window.dialogArguments
alert("您傳遞的參數(shù)為:" + obj.name)
</script>
-------------------------------
2.可以通過window.returnValue向打開對話框的窗口返回信息,當(dāng)然也可以是對象。例如:
------------------------------
parent.htm
復(fù)制代碼 代碼如下:
< type="text/java">
str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");
alert(str);
</script>
modal.htm
復(fù)制代碼 代碼如下:
<script type="text/javascript">
window.returnValue="http://www.dhdzp.com";
</script>
在IE中,我們可以使用showModalDialog來傳值。
語法如下:
vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])
但是.在Firefox中卻沒有showModalDialog方法,不過我們可以用window.open()
語法如下:
oNewWindow = window.open( [sURL] [, sName] [, sFeatures] [, bReplace])
只是,在Firefox下,window.open的參數(shù)中,sFeature多了一些功能設(shè)定,而在FireFox下要讓開啟的視窗跟IE的showModalDialog一樣的話,只要在sFeatures中加個(gè)modal=yes就可以了。
下面用一個(gè)示例來說明其用法。
功能說明:從子窗口中輸入顏色種類提交到父窗口,并添加選項(xiàng)到下拉列表。
a.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>a.html文檔</title>
<script language="javascript">
function openstr()
{
ReturnValue=window.showModalDialog("b.html",window,"dialogWidth=510px;dialogHeight=150px;status=no");
if(ReturnValue && ReturnValue!="")
{
oOption = document.createElement('OPTION');
oOption.text=ReturnValue;
oOption.value=ReturnValue;
document.all.txtselect.add(oOption);
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="txtselect" id="txtselect">
</select>
</label>
<label>
<input type="button" name="Submit" value="打開子窗口" onclick="openstr()" />
</label>
</form>
</body>
</html>
b.html
復(fù)制代碼 代碼如下:
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>b.html文檔</title>
<script language="javascript">
function ClickOk()
{
var t=document.Edit;
var url=t.color.value;
if(url==null||url=="填寫顏色") return(false);
window.returnValue=url;
window.close();
}
</script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="2" align="center" width="300">
<form name="Edit" id="Edit">
<tr>
<td width="30" align="right" height="30">color:</td>
<td height="30"><input type="text" name="color" value="填寫顏色" /></td>
<td width="56" align="center" height="30"><input " type="button" name="bntOk" value="確認(rèn)" onclick="ClickOk();" /> </td>
</tr>
</form>
</table>
</body>
</html>
修改為兼容IE和FireFoxr的代碼如下:
[code]
<!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>a.html文檔</title>
<script type="text/javascript">
function openstr()
{
window.open("b.html","","modal=yes,width=500,height=500,resizable=no,scrollbars=no");
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="txtselect" id="txtselect">
</select>
</label>
<label>
<input type="button" name="Submit" value="打開子窗口" onclick="openstr()" />
</label>
</form>
</body>
</html>
b.html
復(fù)制代碼 代碼如下:
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>b.html文檔</title>
<script type="text/javascript">
function ClickOk()
{
var t=document.Edit;
var color=t.color.value;
if(color==null||color=="填寫顏色") return(false);
var oOption = window.opener.document.createElement('OPTION');
oOption.text=url;
oOption.value=url;
//檢查瀏覽器類型
var bname = navigator.appName;
if (bname.search(/netscape/i) == 0)
{
window.opener.document.getElementById("txtselect").appendChild(oOption);
}
else if (bname.search(/microsoft/i) == 0)
{
window.opener.document.all.txtselect.add(oOption);
}
else
{
}
window.close();
}
</script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="2" align="center" width="300">
<form name="Edit" id="Edit">
<tr>
<td width="30" align="right" height="30">color:</td>
<td height="30"><input type="text" name="color" value="填寫顏色" /></td>
<td width="56" align="center" height="30"><input " type="button" name="bntOk" value="確認(rèn)" onclick="ClickOk();" /> </td>
</tr>
</form>
</table>
</body>
</html>
相關(guān)文章
設(shè)置iframe的document.designMode后僅Firefox中其body.innerHTML為br
設(shè)置iframe的document.designMode為On可以讓其可編輯,一般用在富文本編輯器組件中。這里僅列出各瀏覽器差異2012-02-02
微信小程序bindtap與catchtap的區(qū)別詳解
本文主要介紹了微信小程序bindtap與catchtap的區(qū)別詳解,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09
javascript設(shè)置和獲取cookie的方法實(shí)例詳解
這篇文章主要介紹了javascript設(shè)置和獲取cookie的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析總結(jié)了JavaScript操作cookie簡單實(shí)現(xiàn)數(shù)據(jù)存儲(chǔ)與讀取的相關(guān)技巧,需要的朋友可以參考下2016-01-01
整理Javascript基礎(chǔ)入門學(xué)習(xí)筆記
整理Javascript基礎(chǔ)入門學(xué)習(xí)筆記,之前一系列的文章是跟我學(xué)習(xí)Javascript,本文就是進(jìn)一步學(xué)習(xí)javascript,希望大家繼續(xù)關(guān)注2015-11-11
JS Object構(gòu)造函數(shù)之Object.freeze
這篇文章主要介紹了JS Object構(gòu)造函數(shù)之Object.freeze,對JS感興趣的同學(xué),可以深入了解下2021-04-04
讓javascript加載速度倍增的方法(解決JS加載速度慢的問題)
這篇文章主要介紹了讓javascript加載速度倍增的方法,通過document.write輸出js解決廣告加載速度慢的問題,需要的朋友可以參考下2014-12-12

