`
vfh615gc
  • 浏览: 14381 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

window.showModalDialog使用手册

 
阅读更多

window.showModalDialog使用手册
2011年03月01日
   基本介绍: 
  showModalDialog()                              (IE 4+ 支持) 
  showModelessDialog()                         (IE 5+ 支持) 
  window.showModalDialog()                 方法用来创建一个显示HTML内容的模态对话框。 
  window.showModelessDialog()            方法用来创建一个显示HTML内容的非模态对话框。 
  使用方法: 
  vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures]) 
  vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures]) 
  参数说明: 
  sURL                --   必选参数,类型:字符串。用来指定对话框要显示的文档的URL。 
  vArguments   --    可选参数,类型:变体。用来向对话框传递参数。传递的参数类型不限,包括数组等。对话框通过window.dialogArguments来取得传递进来的参数。 
  sFeatures       --    可选参数,类型:字符串。用来描述对话框的外观等信息,可以使用以下的一个或几个,用分号“;”隔开。 
  ---------------- 
  1.   dialogHeight:   对话框高度,不小于100px 
  2.   dialogWidth:   对话框宽度。 
  3.   dialogLeft:    离屏幕左的距离。 
  4.   dialogTop:    离屏幕上的距离。 
  5.   center:         { yes | no | 1 | 0 } :             是否居中,默认yes,但仍可以指定高度和宽度。 
  6.   help:            {yes | no | 1 | 0 }:               是否显示帮助按钮,默认yes。 
  7.   resizable:      {yes | no | 1 | 0 } [IE5+]:    是否可被改变大小。默认no。 
  8.   status:         {yes | no | 1 | 0 } [IE5+]:     是否显示状态栏。默认为yes[ Modeless]或no[Modal]。 
  9.   scroll:           { yes | no | 1 | 0 | on | off }:是否显示滚动条。默认为yes。 
  下面几个属性是用在HTA中的,在一般的网页中一般不使用。 
  10.   dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印预览时对话框是否隐藏。默认为no。 
  11.   edge:{ sunken | raised }:指明对话框的边框样式。默认为raised。 
  12.   unadorned:{ yes | no | 1 | 0 | on | off }:默认为no。 
  参数传递: 
  1.   要想对话框传递参数,是通过vArguments来进行传递的。类型不限制,对于字符串类型,最大为4096个字符。也可以传递对象,例如: 
  ------------------------------- 
  parent.htm 
   
  var obj = new Object(); 
  obj.name="51js"; 
  window.showModalDialog("modal.htm",obj,"dialogWidt h=200px;dialogHeight=100px"); 
   
  modal.htm 
   
  var obj = window.dialogArguments 
  alert("您传递的参数为:" + obj.name) 
   
  ------------------------------- 
  2.   可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例如: 
  ------------------------------ 
  parent.htm 
   
  str =window.showModalDialog("modal.htm",,"dialogWidth= 200px;dialogHeight=100px"); 
  alert(str); 
   
  modal.htm 
   
  window.returnValue="http://homepage.yesky.com"; 
   
  一、showModalDialog和showModelessDialog有什么不同? 
  showModalDialog:被打开后就会始终保持输入焦点。除非对话框被关闭,否则用户无法切换到主窗口。类似alert的运行效果。 
  showModelessDialog:被打开后,用户可以随机切换输入焦点。对主窗口没有任何影响(最多是被挡住一下而以。:P) 
  二、怎样才让在showModalDialog和showModelessDialog的超连接不弹出新窗口? 
  在被打开的网页里加上就可以了。这句话一般是放在和之间的。 
  三、怎样才刷新showModalDialog和showModelessDialog里的内容? 
  在showModalDialog和showModelessDialog里是不能按F5刷新的,又不能弹出菜单。这个只能依靠javascript了,以下是相关代码: 
   
  reload... 
  将filename.htm替换成网页的名字然后将它放到你打开的网页里,按F5就可以刷新了,注意,这个要配合使用,不然你按下F5会弹出新窗口的。 
  四、如何用javascript关掉showModalDialog(或showModelessDialog)打开的窗口。 
   
  也要配合,不然会打开一个新的IE窗口,然后再关掉的。 
  五、showModalDialog和showModelessDialog数据传递技巧。 
  (作者语:本来想用一问一答形式来写的,但是我想不出这个怎么问,所以只好这样了。) 
  这个东西比较麻烦,我改了好几次了不是没办法说明白(语文水平越来越差了),只好用个例子说明了。 
  例子: 
  现在需要在一个showModalDialog(或showModelessDialog)里读取或设置一个变量var_name 
  一般的传递方式: 
  window.showModalDialog("filename.htm",var_name) 
  //传递var_name变量 
  在showModalDialog(或showModelessDialog)读取和设置时: 
  alert(window.dialogArguments)//读取var_name变量 
  window.dialogArguments="oyiboy"//设置var_name变量 
  这种方式是可以满足的,但是当你想在操作var_name同时再操作第二个变理var_id时呢?就无法再进行操作了。这就是这种传递方式的局限性。 
  以下是我建议使用的传递方式: 
  window.showModalDialog("filename.htm",window) 
  //不管要操作什么变量,只直传递主窗口的window对象 
  在showModalDialog(或showModelessDialog)读取和设置时: 
  alert(window.dialogArguments.var_name)//读取var_name变量 
  window.dialogArguments.var_name="oyiboy"//设置var_name变量 
  同时我也可以操作var_id变量 
  alert(window.dialogArguments.var_id)//读取var_id变量 
  window.dialogArguments.var_id="001"//设置var_id变量 
  同样还可以对主窗口的任何对象进行操作,如form对象里的元素。 
  window.dialogArguments.form1.index1.value="这是在设置index1元素的值" 
  在父页面中用onClick=""var reVal = window.showModalDialog('changephoto.htm','dialogWi dth:500px;dialogHeight:300px;help:no');if (typeof(reVal) != 'undefined') {form.textname.value=reVal;}"" style=""cursor:hand "">点击这里修改图片 
  在字窗口'changephoto.htm'中打开一个框架集,框架集中包含一个asp文件,先将asp的值返回到changephoto.htm中 再将这个值返回到主页面中 
  changephoto.htm:  
  function onClose() { window.returnValue = form1.save.value;//也可以将window.returnValue改成window.dialogArguments.oblogform.blogimage.value window.close(); } 
  asp文件:parent.document.form1.save.value ="值或变量"; 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics