window.showModalDialog的基本用法

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,IE4中dialogHeight 和 dialogWidth 默认的单位是em,而IE5中是px,为方便其见,在定义modal方式的对话框时,用px做单位。 
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个字符。也可以传递对象,例如:

<script> 
var obj = new Object(); 
obj.name="ttop"; 
window.showModalDialog("test.htm",obj,"dialogWidth=200px;dialogHeight=100px"); 
</script> 
test.htm 
<script> 
var obj = window.dialogArguments 
alert("您传递的参数为:" + obj.name) 
</script>

2.可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例如:

<script> 
str =window.showModalDialog("test.htm",,"dialogWidth=200px;dialogHeight=100px"); 
alert(str); 
</script> 
test.htm 
<script> 
window.returnValue="/"; 
</script> 
一、showModalDialog和showModelessDialog有什么不同? 
  showModalDialog:被打开后就会始终保持输入焦点。除非对话框被关闭,否则用户无法切换到主窗口。类似alert的运行效果。 
  showModelessDialog:被打开后,用户可以随机切换输入焦点。对主窗口没有任何影响(最多是被挡住一下而以。:P)

二、怎样才让在showModalDialog和showModelessDialog的超连接不弹出新窗口? 
  在被打开的网页里加上<base target="_self">就可以了。这句话一般是放在<html>和<body>之间的。

三、怎样才刷新showModalDialog和showModelessDialog里的内容? 
  在showModalDialog和showModelessDialog里是不能按F5刷新的,又不能弹出菜单。这个只能依靠javascript了,以下是相关代码:

<body onkeydown="if (event.keyCode==116){reload.click()}"> 
<a id="reload" href="filename.htm" style="display:none">reload...</a>

  将filename.htm替换成网页的名字然后将它放到你打开的网页里,按F5就可以刷新了,注意,这个要配合<base target="_self">使用,不然你按下F5会弹出新窗口的。

四、如何用javascript关掉showModalDialog(或showModelessDialog)打开的窗口。 
  <input type="button" value="关闭" onclick="window.close()"> 
  也要配合<base target="_self">,不然会打开一个新的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','dialogWidth:500px;dialogHeight:300px;help:no');if (typeof(reVal) != 'undefined') {form.textname.value=reVal;}"" style=""cursor:hand "">点击这里修改图片. 
在字窗口'changephoto.htm'中打开一个框架集,框架集中包含一个asp文件,先将asp的值返回到changephoto.htm中 再将这个值返回到主页面中 
changephoto.htm: <input type=button onclick="onClose();" value=" 关 闭 "> 
function onClose() { window.returnValue = form1.save.value;//也可以将window.returnValue改成window.dialogArguments.oblogform.blogimage.value window.close(); }

转载自:http://www.cnblogs.com/hynxy0115/archive/2009/03/18/1415654.html

window.showModalDialog()之返回值的更多相关文章

  1. window.open 和showModalDialog的返回值

    方法: 1:  在父级页面 test.aspx 的点击<input type="button" id="btnShow" onclick="sh ...

  2. window.open如何返回值给父窗口

    父窗口代码 function showMyWindowNew() { var iTop = (window.screen.availHeight - 30 - 450) / 2; //获得窗口的水平位 ...

  3. JavaScript 返回值

    Window.Open()返回值: 利用window.open(‘NewWindow.html’):打开新的窗口NewWindow.html后,如果有返回值需要处理,应通过window.opener. ...

  4. window.showModalDialog返回值和window.open返回值实例详解

    最近在谷歌浏览器下发现一个问题,就是使用谷歌浏览器已经不兼容window.showModalDialog了,所以还是改成使用window.open(). 一.window.showModalDialo ...

  5. 父窗口window.showModalDialog传值 子窗口window.returnValue返回值

    父窗口打开子窗口页面: var fatherWindow = document.all.dealReason;//想传的值 win = window.showModalDialog(strUrl, f ...

  6. 解决chrome浏览器无法得到window.showModalDialog返回值的问题

    父页面处理: function ProductList() {   var TypeID = window.document.getElementById("Type").valu ...

  7. asp.net 中点击button弹出模式对话框,选择值后返回到页面中(window.showModalDialog实现)

    <td>现从事专业</td><td>       <asp:TextBox ID="tbMajor" runat="server ...

  8. window.showModalDialog的传值和返回值

    window.showModalDialog(URL,dialogArgments,features) 打开一个新窗口 URL为要将打开的网页地址. dialogArgments为设定好传递给新视窗网 ...

  9. IE 中创建 子窗口 传值 与接收值 【window.showModalDialog】

    父窗口 创建一个窗口 var backinfo = window.showModalDialog('UserSelect.aspx', '', 'dialogHeight=600px; dialogW ...

随机推荐

  1. JDK自带的定时任务

    import java.util.TimerTask; /** * 实现定时任务 * */ public class MyTimerTask extends TimerTask { @Override ...

  2. struts2中配置文件加载的顺序是什么?

    struts2的StrutsPrepareAndExecuteFilter拦截器中对Dispatcher进行了初始化 在Dispatcher类的init方法中定义了配置文件的加载顺序(下面是源码) p ...

  3. PHP资源,库,工具大全

    内容包括:库.框架.模板.安全.代码分析.日志.第三方库.配置工具.Web 工具.书籍.电子书.经典博文等等. 大家可以搜索其它语言,如awesome-java的https://github.com/ ...

  4. oracle中nvl()函数

    oracle中nvl()函数  oracle的nvl函数的使用方法 通过查询获得某个字段的合计值,假设这个值位null将给出一个预设的默认值  select nvl(sum(t.dwxhl),1) f ...

  5. 安装Hadoop 1.1.2 (三 安装配置Hadoop)

    1 tar -zxvf hadoop-1.1.2.tar.gz 2 在hadoop/conf目录 (1) 编辑 hadoop-env.sh export JAVA_HOME=/usr/java/jdk ...

  6. 【智力题】IO——行测、笔试、面试中遇到的

    昨天(05.23)下午去参加了明源软件的暑期实习宣讲+笔试,第一次听说这个行业,行业和笔试风格完全不一样啊,5道行测智力题+1个问答+ 斐波那契数列 + 洗牌算法(思想.流程图.代码),今年回来后线上 ...

  7. 【BZOJ3060】[Poi2012]Tour de Byteotia 并查集

    [BZOJ3060][Poi2012]Tour de Byteotia Description 给定一个n个点m条边的无向图,问最少删掉多少条边能使得编号小于等于k的点都不在环上. Input     ...

  8. Google的Guava之IO升华

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/luo201227/article/details/36413279 程序员在开发过程中,使用文件的几 ...

  9. linux基础part2

    linux基础 一.linux基础命令 1.pwd:用来显示当前目录位置 2.cd:用来切换目录位置.(eg:cd...cd../...cd-.cd~) 3.ls:用来查看目录或文件信息(eg:ls ...

  10. DNS 原理入门 (转)

    DNS 是互联网核心协议之一.不管是上网浏览,还是编程开发,都需要了解一点它的知识. 本文详细介绍DNS的原理,以及如何运用工具软件观察它的运作.我的目标是,读完此文后,你就能完全理解DNS. 一.D ...