时间: 2021-07-31 作者:daque
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 可选参数,典型:字符串。用来刻画对话框的表面等消息,不妨运用以次的一个或几个,用分号“;”隔绝。 dialogheight 对话框莫大,不小于100px,IE4中dialogheight 和 dialogwidth 默许的单元是em,而IE5中是px,为简单其见,在设置modal办法的对话框时,用px做单元。 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 } [ie5+]:能否表露状况栏。默许为yes[ modeless]或no[modal]。 scroll:{ yes | no | 1 | 0 | on | off }:指明对话框能否表露震动条。默许为yes。
再有几个属性是用在hta中的,在普遍的网页中普遍不运用。 dialoghide:{ yes | no | 1 | 0 | on | off }:在打字与印刷大概打字与印刷预览时对话框能否湮没。默许为no。 edge:{ sunken | raised }:指明对话框的边框款式。默许为raised。 unadorned:{ yes | no | 1 | 0 | on | off }:默许为no。
传入参数: 要想对话框传播参数,是经过varguments来举行传播的。典型不控制,对于字符串典型,最大为4096个字符。也不妨传播东西,比方:
test1.htm<script> var mxh1 = new array("mxh","net_lover","孟子e章") var mxh2 = window.open("about:blank","window_mxh") // 向对话框传播数组 window.showmodaldialog("test2.htm",mxh1) // 向对话框传播window东西 window.showmodaldialog("test3.htm",mxh2)</script>test2.htm<script> var a = window.dialogarguments alert("您传播的参数为:" + a)</script> test3.htm<script> var a = window.dialogarguments alert("您传播的参数为window东西,称呼:" + a.name) </script>
不妨经过window.returnvalue向翻开对话框的窗口归来消息,固然也不妨是东西。比方:
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>
罕见题目:1,怎样在模态对话框中举行提交而不新开窗口? 即使你 的 欣赏器是ie5.5+,不妨在对话框中运用带name属性的iframe,提交时不妨拟订target为该iframe的name。对于ie4+,你不妨用莫大为0的frame来作。比方:
test6.htm<script> window.showmodaldialog("test7.htm") </script> test7.htmif(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,不妨经过http://servername/virtualdirname/test.htm?name=mxh办法径直向对话框传播参数吗? 谜底是不许。但在frame里是不妨的。