原文出處:http://hi.baidu.com/en0721/blog/item/7097c9d3cdf05bdea8ec9a48.html
Javascript有許多內(nèi)建的方法來(lái)產(chǎn)生對(duì)話框,如:window.alert(), window.confirm(),window.prompt().等。 然而IE提供更多的方法支持對(duì)話框。如:
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 onclick="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里是可以的。
FeedBack:
# re: [轉(zhuǎn)]Window.ShowModalDialog使用詳解
只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。 | ||
![]() |
||
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問(wèn)
管理
|
||
相關(guān)文章:
|
||
| |||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
29 | 30 | 1 | 2 | 3 | 4 | 5 | |||
6 | 7 | 8 | 9 | 10 | 11 | 12 | |||
13 | 14 | 15 | 16 | 17 | 18 | 19 | |||
20 | 21 | 22 | 23 | 24 | 25 | 26 | |||
27 | 28 | 29 | 30 | 31 | 1 | 2 | |||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
生活將我們磨圓,是為了讓我們滾得更遠(yuǎn)——“圓”來(lái)如此。
我的作品:
玩轉(zhuǎn)Axure RP (2015年12月出版)

Power Designer系統(tǒng)分析與建模實(shí)戰(zhàn) (2015年7月出版)
Struts2+Hibernate3+Spring2 (2010年5月出版)
我的作品:
玩轉(zhuǎn)Axure RP (2015年12月出版)

Power Designer系統(tǒng)分析與建模實(shí)戰(zhàn) (2015年7月出版)

Struts2+Hibernate3+Spring2 (2010年5月出版)

留言簿(263)
隨筆分類(lèi)
- Ajax(3)
- Ant(1)
- Auto Code(4)
- Cewolf
- CMMI(1)
- CSS(2)
- CVS(1)
- database(15)
- Design Pattern(11)
- Eclipse BIRT(1)
- EJB
- extremecomponents(1)
- GIS(2)
- Hibernate(8)
- iBATIS(2)
- IDE(1)
- Inno Setup(2)
- IT評(píng)論(2)
- Java(36)
- Javascript(32)
- JBoss(1)
- JFreeChart(3)
- JFreeReport(3)
- JSF
- Linux(3)
- MySql(11)
- Open Source(4)
- Oracle(5)
- Other(13)
- Spring(12)
- Sql Server(1)
- Struts(7)
- Struts2(8)
- Tomcat
- UML
- Web(8)
- Web Service(3)
- Workflow
- 產(chǎn)品原型設(shè)計(jì)(8)
- 似水流年(13)
- 協(xié)議(12)
- 原創(chuàng)小說(shuō)(1)
- 技術(shù)評(píng)論
- 架構(gòu)師之路(12)
- 電信知識(shí)(3)
- 網(wǎng)絡(luò)通信相關(guān)(11)
- 職場(chǎng)感悟(6)
- 解決方案(12)
- 項(xiàng)目管理(8)
隨筆檔案
- 2016年3月 (2)
- 2015年11月 (1)
- 2015年9月 (1)
- 2015年6月 (3)
- 2015年5月 (4)
- 2014年12月 (2)
- 2014年7月 (1)
- 2014年6月 (1)
- 2014年5月 (2)
- 2014年1月 (2)
- 2013年10月 (1)
- 2013年8月 (1)
- 2013年7月 (1)
- 2013年4月 (1)
- 2013年2月 (1)
- 2012年11月 (2)
- 2012年10月 (1)
- 2012年1月 (1)
- 2011年11月 (8)
- 2011年10月 (4)
- 2011年9月 (1)
- 2011年8月 (2)
- 2011年7月 (5)
- 2011年2月 (2)
- 2011年1月 (1)
- 2010年12月 (3)
- 2010年11月 (9)
- 2010年9月 (1)
- 2010年7月 (2)
- 2010年6月 (2)
- 2010年5月 (5)
- 2010年4月 (2)
- 2009年12月 (4)
- 2009年11月 (2)
- 2009年10月 (1)
- 2009年9月 (3)
- 2009年8月 (5)
- 2009年7月 (5)
- 2009年5月 (1)
- 2008年10月 (3)
- 2008年9月 (3)
- 2008年8月 (1)
- 2008年6月 (2)
- 2008年5月 (3)
- 2008年4月 (2)
- 2008年2月 (2)
- 2008年1月 (11)
- 2007年12月 (9)
- 2007年11月 (7)
- 2007年10月 (9)
- 2007年9月 (12)
- 2007年8月 (24)
- 2007年7月 (10)
- 2007年6月 (2)
- 2007年5月 (3)
- 2007年4月 (18)
- 2007年3月 (24)
- 2007年2月 (24)
文章分類(lèi)
相冊(cè)
- java學(xué)習(xí)相關(guān)
- other
- 產(chǎn)品經(jīng)理相關(guān)
- 圖書(shū)相關(guān)
- 工具相關(guān)
- 日歷
- 架構(gòu)師相關(guān)
- 設(shè)計(jì)模式相關(guān)
- 貼圖
- 走走拍拍
- 飯團(tuán)
關(guān)注blog
積分與排名
- 積分 - 2296377
- 排名 - 3
最新評(píng)論

- 1.?re: 新書(shū)推薦:《Power Designer系統(tǒng)分析與建模實(shí)戰(zhàn)》
-
你好。買(mǎi)了書(shū),麻煩把書(shū)中的樣例工程文件發(fā)給我。非常感謝。
我的郵箱:wen027andy@163.com - --文良
- 2.?re: 新書(shū)推薦:《Power Designer系統(tǒng)分析與建模實(shí)戰(zhàn)》
-
@智祿
謝謝指出,下次改版修正:) - --阿蜜果
- 3.?re: 新書(shū)推薦:《Power Designer系統(tǒng)分析與建模實(shí)戰(zhàn)》
-
6.1.3 9.存儲(chǔ)函數(shù)
存儲(chǔ)函數(shù)與存儲(chǔ)函數(shù)類(lèi)似,……
此處應(yīng)該是:存儲(chǔ)函數(shù)與存儲(chǔ)過(guò)程類(lèi)似,……
我買(mǎi)的是多看上的電子版,請(qǐng)修改
- --智祿
- 4.?re: 新書(shū)推薦:《Power Designer系統(tǒng)分析與建模實(shí)戰(zhàn)》
-
您好,今天買(mǎi)了您的這本書(shū),為了更好的學(xué)習(xí),麻煩將書(shū)中的樣例工程文件發(fā)給我,萬(wàn)分感謝,感謝作者寫(xiě)出這么好的書(shū),我特別需要,祝大賣(mài)~~
yaozhilu@foxmail.com - --智祿
- 5.?re: 新書(shū)推薦:《Power Designer系統(tǒng)分析與建模實(shí)戰(zhàn)》
-
您好,書(shū)不錯(cuò),已經(jīng)買(mǎi)了,麻煩發(fā)套樣例工程吧,最好詳細(xì)點(diǎn)的,萬(wàn)分感激!
jackylee365@163.com - --李成龍
閱讀排行榜
- 1.?常用加密算法的Java實(shí)現(xiàn)總結(jié)(二)——對(duì)稱(chēng)加密算法DES、3DES和AES(143718)
- 2.?用Ant實(shí)現(xiàn)Java項(xiàng)目的自動(dòng)構(gòu)建和部署(123992)
- 3.?異常備忘:java.lang.UnsupportedClassVersionError: Bad version number in .class file(114282)
- 4.?Java代碼規(guī)范、格式化和checkstyle檢查配置文檔(71836)
- 5.?常用加密算法的Java實(shí)現(xiàn)總結(jié)(一)——單向加密算法MD5和SHA(62394)
- 6.?通用權(quán)限管理系統(tǒng)設(shè)計(jì)篇(三)——概要設(shè)計(jì)說(shuō)明書(shū)(61754)
- 7.?使用XFire+Spring構(gòu)建Web Service(一)——helloWorld篇(53673)
- 8.?基于注解的Spring MVC+Hibernate簡(jiǎn)單入門(mén)(52601)
- 9.?在阿里云Linux服務(wù)器上安裝MySQL(49660)
- 10.?關(guān)系型數(shù)據(jù)的分布式處理系統(tǒng)MyCAT(1)—概述和基本使用教程(47778)
評(píng)論排行榜
- 1.?使用XFire+Spring構(gòu)建Web Service(二)(102)
- 2.?使用XFire+Spring構(gòu)建Web Service(一)——helloWorld篇(70)
- 3.?通用權(quán)限管理系統(tǒng)設(shè)計(jì)篇(三)——概要設(shè)計(jì)說(shuō)明書(shū)(64)
- 4.?異常備忘:java.lang.UnsupportedClassVersionError: Bad version number in .class file(54)
- 5.?通用權(quán)限管理設(shè)計(jì)篇(二)——數(shù)據(jù)庫(kù)設(shè)計(jì)(40)