[转]showModalDialog()、showModelessDialog()方法使用详解
showModalDialog() (IE 4+ 支持)
showModelessDialog() (IE 5+ 支持)
?window.showModalDialog()方法用來(lái)創(chuàng)建一個(gè)顯示HTML內(nèi)容的模態(tài)對(duì)話框,由于是對(duì)話框,因此它并沒(méi)有一般用window.open()打開(kāi)的窗口的所有屬性。
?window.showModelessDialog()方法用來(lái)創(chuàng)建一個(gè)顯示HTML內(nèi)容的非模態(tài)對(duì)話框。
?當(dāng)我們用showModelessDialog()打開(kāi)窗口時(shí),不必用window.close()去關(guān)閉它,當(dāng)以非模態(tài)方式[IE5]打開(kāi)時(shí), 打開(kāi)對(duì)話框的窗口仍可以進(jìn)行其他的操作,即對(duì)話框不總是最上面的焦點(diǎn),當(dāng)打開(kāi)它的窗口URL改變時(shí),它自動(dòng)關(guān)閉。而模態(tài)[IE4]方式的對(duì)話框始終有焦點(diǎn)(焦點(diǎn)不可移走,直到它關(guān)閉)。模態(tài)對(duì)話框和打開(kāi)它的窗口相聯(lián)系,因此我們打開(kāi)另外的窗口時(shí),他們的鏈接關(guān)系依然保存,并且隱藏在活動(dòng)窗口的下面。
使用方法如下:
?vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])
?vReturnValue = window.showModelessDialog(sURL [, vArguments] [, sFeatures])
參數(shù)說(shuō)明:
?sURL
?必選參數(shù),類(lèi)型:字符串。用來(lái)指定對(duì)話框要顯示的文檔的URL。
?vArguments
?可選參數(shù),類(lèi)型:變體。用來(lái)向?qū)υ捒騻鬟f參數(shù)。傳遞的參數(shù)類(lèi)型不限,包括數(shù)組等。對(duì)話框通過(guò)window.dialogArguments來(lái)取得傳遞進(jìn)來(lái)的參數(shù)。
?sFeatures
?可選參數(shù),類(lèi)型:字符串。用來(lái)描述對(duì)話框的外觀等信息,可以使用以下的一個(gè)或幾個(gè),用分號(hào)“;”隔開(kāi)。
??dialogHeight 對(duì)話框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默認(rèn)的單位是em,而IE5中是px,為方便其見(jiàn),在定義modal方式的對(duì)話框時(shí),用px做單位。
? dialogWidth: 對(duì)話框?qū)挾取?br />? dialogLeft: 距離桌面左的距離。
? dialogTop: 離桌面上的距離。
? center: {yes | no | 1 | 0 }:窗口是否居中,默認(rèn)yes,但仍可以指定高度和寬度。
? help: {yes | no | 1 | 0 }:是否顯示幫助按鈕,默認(rèn)yes。
? resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改變大小。默認(rèn)no。
? status: {yes | no | 1 | 0 } [IE5+]:是否顯示狀態(tài)欄。默認(rèn)為yes[ Modeless]或no[Modal]。
??scroll:{ yes | no | 1 | 0 | on | off }:指明對(duì)話框是否顯示滾動(dòng)條。默認(rèn)為yes。
??還有幾個(gè)屬性是用在HTA中的,在一般的網(wǎng)頁(yè)中一般不使用。
??dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印預(yù)覽時(shí)對(duì)話框是否隱藏。默認(rèn)為no。
??edge:{ sunken | raised }:指明對(duì)話框的邊框樣式。默認(rèn)為raised。
??unadorned:{ yes | no | 1 | 0 | on | off }:默認(rèn)為no。
?傳入?yún)?shù):
?要想對(duì)話框傳遞參數(shù),是通過(guò)vArguments來(lái)進(jìn)行傳遞的。類(lèi)型不限制,對(duì)于字符串類(lèi)型,最大為4096個(gè)字符。也可以傳遞對(duì)象,例如:
?test1.htm
?====================
?<script>
??var mxh1 = new Array("mxh","net_lover","孟子E章")
??var mxh2 = window.open("about:blank","window_mxh")
??// 向?qū)υ捒騻鬟f數(shù)組
??window.showModalDialog("test2.htm",mxh1)
??// 向?qū)υ捒騻鬟fwindow對(duì)象
??window.showModalDialog("test3.htm",mxh2)
?</script>
?test2.htm
?====================
?<script>
??var a = window.dialogArguments
??alert("您傳遞的參數(shù)為:" + a)
?</script>
?test3.htm
?====================
?<script>
??var a = window.dialogArguments
??alert("您傳遞的參數(shù)為window對(duì)象,名稱(chēng):" + a.name)
?</script>
?可以通過(guò)window.returnValue向打開(kāi)對(duì)話框的窗口返回信息,當(dāng)然也可以是對(duì)象。例如:
?test4.htm
?===================
?<script>
??var a = window.showModalDialog("test5.htm")
??for(i=0;i<a.length;i++) alert(a[i])
?</script>
?test5.htm
?===================
?<script>
?function sendTo()
?{
??var a=new Array("a","b")
??window.returnValue = a
??window.close()
?}
?</script>
?<body>
?<form>
??<input value="返回" type=button οnclick="sendTo()">
?</form>
?常見(jiàn)問(wèn)題:
?1,如何在模態(tài)對(duì)話框中進(jìn)行提交而不新開(kāi)窗口?
?如果你 的 瀏覽器是IE5.5+,可以在對(duì)話框中使用帶name屬性的iframe,提交時(shí)可以制定target為該iframe的name。對(duì)于IE4+,你可以用高度為0的frame來(lái)作:例子,
?test6.htm
?===================
?<script>
??window.showModalDialog("test7.htm")
?</script>
?test7.htm
?===================
?if(window.location.search) alert(window.location.search)
?<frameset rows="0,*">
??<frame src="about:blank">
??<frame src="test8.htm">
?</frameset>
?test8.htm
?===================
?<form target="_self" method="get">
?<input name=txt value="test">
?<input type=submit>
?</form>
?<script>
?if(window.location.search) alert(window.location.search)
?</script>
?2,可以通過(guò)http://servername/virtualdirname/test.htm?name=mxh方式直接向?qū)υ捒騻鬟f參數(shù)嗎?
?答案是不能。但在frame里是可以的。
總結(jié)
以上是生活随笔為你收集整理的[转]showModalDialog()、showModelessDialog()方法使用详解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: [转]在ASP.NET中如何用C#.NE
- 下一篇: 需求分析内容。