window.returnValue:模態窗口中向調用窗口返回的值
例如,A打開B ,B關閉時就可以向A返回一個returnvalue ,A怎樣獲得B返回的值呢?
1 function modalDialogShow(url,width,height){ 2 if(url.indexOf("?")==-1) 3 url=url+"?ffilter=image";//默認只顯示圖片文件 4 else 5 url=url+"&ffilter=image"; 6 var arrTmp = 7 window.showModalDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:1;help:0;resizable:1;maximize:1"); 8 //將returnvalue賦值給arrTmp 9 setAssetValue(arrTmp); //將arrTmp 賦值給附件地址框 10 }
showModalDialog()、showModelessDialog()方法使用詳解
Javascript有許多內建的方法來產生對話框,如:window.alert(), window.confirm(),window.prompt().等, 然而IE提供更多的方法支持對話框。如:
showModalDialog() (IE 4+ 支持) ,showModelessDialog() (IE 5+ 支持) 。
window.showModalDialog()方法用來創建一個顯示HTML內容的模態對話框,由於是對話框,因此它並沒有一般用window.open()打開的窗口的所有屬性。
window.showModelessDialog()方法用來創建一個顯示HTML內容的非模態對話框。
當我們用showModelessDialog()打開窗口時,不必用window.close()去關閉它,當以非模態方式[IE5]打開時, 打開對話框的窗口仍可以進行其他的操作,即對話框不總是最上面的焦點,當打開它的窗口URL改變時,它自動關閉。而模態[IE4]方式的對話框始終有焦點(焦點不可移走,直到它關閉)。模態對話框和打開它的窗口相聯系,因此我們打開另外的窗口時,他們的鏈接關系依然保存,並且隱藏在活動窗口的下面。
使用方法如下:
vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])
vReturnValue = window.showModelessDialog(sURL [, vArguments] [, sFeatures])
參數說明:
sURL 必選參數,類型:字符串。用來指定對話框要顯示的文檔的URL。
vArguments 可選參數,類型:變體。用來向對話框傳遞參數。傳遞的參數類型不限,包括數組等。對話框通過window.dialogArguments來取得傳遞進來的參數。
sFeatures 可選參數,類型:字符串。用來描述對話框的外觀等信息,可以使用以下的一個或幾個,用分號“;”隔開。
window.showModalDialog()方法用來創建一個顯示HTML內容的模態對話框,由於是對話框,因此它並沒有一般用window.open()打開的窗口的所有屬性。
window.showModelessDialog()方法用來創建一個顯示HTML內容的非模態對話框。
當我們用showModelessDialog()打開窗口時,不必用window.close()去關閉它,當以非模態方式[IE5]打開時, 打開對話框的窗口仍可以進行其他的操作,即對話框不總是最上面的焦點,當打開它的窗口URL改變時,它自動關閉。而模態[IE4]方式的對話框始終有焦點(焦點不可移走,直到它關閉)。模態對話框和打開它的窗口相聯系,因此我們打開另外的窗口時,他們的鏈接關系依然保存,並且隱藏在活動窗口的下面。
使用方法如下:
vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])
vReturnValue = window.showModelessDialog(sURL [, vArguments] [, sFeatures])
參數說明:
sURL 必選參數,類型:字符串。用來指定對話框要顯示的文檔的URL。
vArguments 可選參數,類型:變體。用來向對話框傳遞參數。傳遞的參數類型不限,包括數組等。對話框通過window.dialogArguments來取得傳遞進來的參數。
sFeatures 可選參數,類型:字符串。用來描述對話框的外觀等信息,可以使用以下的一個或幾個,用分號“;”隔開。
參數名稱 | 描述 |
dialogHeight | 對話框高度 |
dialogWidth | 對話框寬度 |
dialogLeft | 距離桌面左的距離 |
dialogTop | 離桌面上的距離 |
center: {yes | no | 1 | 0 } | 窗口是否居中,默認yes,但仍可以指定高度和寬度。 |
help: {yes | no | 1 | 0 } | 是否顯示幫助按鈕,默認yes。 |
resizable: {yes | no | 1 | 0 } | [IE5+]:是否可被改變大小。默認no。 |
status: {yes | no | 1 | 0 } | 是否顯示狀態欄。默認為yes[ Modeless]或no[Modal]。 |
scroll:{ yes | no | 1 | 0 | on | off } | 指明對話框是否顯示滾動條。默認為yes |
dialogHide:{ yes | no | 1 | 0 | on | off } | 在打印或者打印預覽時對話框是否隱藏。默認為no。 |
edge:{ sunken | raised } | 指明對話框的邊框樣式。默認為raised。 |
unadorned:{ yes | no | 1 | 0 | on | off } | 默認為no |
window.showModalDialog和window.returnValue的應用
<%--fireForm.htm:點擊“上傳”按鈕彈出內部窗口(showModalDialog)--%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>無標題文檔</title> <script language="javascript"> function onObjMore(url,name,height,width,formName) { //window.alert(formName.file.type); var feature = "dialogWidth:"+width+"px;dialogHeight:"+height+"px;scroll:yes;status:no;help:no;center:1"; var returnTarget = window.showModalDialog(url, name, feature); if(returnTarget != undefined && returnTarget.length > 1) { //document.location = returnTarget; formName.file.value=returnTarget; } return false; } </script> <link href="css/aljoin.css" rel="stylesheet" type="text/css"> </head> <body> <form name="proForm" method="post" action=""> <table width="400" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="93" height="25" style="white-space:nowrap " nowrap>文件</td> <td width="307" height="25"><input name="file" type="text" id="file"></td> </tr> <tr> <td height="25"> </td> <td height="25"><input type="button" name="Submit" value="上傳文件" onClick="onObjMore('upfile.htm','upfile',300,300,proForm)"></td> </tr> </table> </form> </body> </html> <%--upfile.htm:點擊”關閉”按鈕返回window.returnValue值給opener,代碼如下: --%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>無標題文檔</title> <script language="javascript"> function exit() { window.returnValue = "images/upload/2004080512.jpg"; window.close(); } </script> </head> <body> <input name="" type="button" value="關閉窗口" onClick="exit()"> </body> </html>