本文转载:http://www.cnblogs.com/sunnycoder/archive/2010/05/05/1728047.html

基本知识

l  showModalDialog() (IE 4+ 支持)

l  showModelessDialog() (IE 5+ 支持)

l  window.showModalDialog()方法用来创建一个显示HTML内容的模态对话框。

l  window.showModelessDialog()方法用来创建一个显示HTML内容的非模态对话框。

使用方法

var returnValue = window.showModalDialog(sURL[,vArguments][,sFeatures]);

var returnValue = window.showModelessDialog(sURL[,vArguments][,sFeatures]);

参数说明

参数名称

性质

类型

作用

sURL

必选

字符串

用来指定对话框要显示的网页的URL。

vArguments

可选

任何类型

用来向对话框传递参数。参数类型不限。

对话框通过window.dialogArguments来取得传递进来的参数。

sFeatures

可选

字符串

用来描述对话框的外观等信息

sFeatures参数说明

参数名称

参数属性

说明

dialogHeight

npx

对话框高度,不小于100px

dialogWidth

npx

对话框宽度

dialogLeft

npx

离主窗口左的距离

dialogTop

npx

离主窗口上的距离

center

{yes | no | 1 | 0 }

窗口是否居中,默认yes

help

{yes | no | 1 | 0 }

是否显示帮助按钮,默认yes

resizable

{yes | no | 1 | 0 }

是否可改变大小,默认no

status

{yes | no | 1 | 0 }

是否显示状态栏,默认为yes[ Modeless]或no[Modal]

dialogHide

{ yes | no | 1 | 0 | on | off }

在打印或者打印预览时对话框是否隐藏,默认为no

scroll

{ yes | no | 1 | 0 | on | off }

指明对话框是否显示滚动条,默认为yes

edge

{ sunken | raised }

指明对话框的边框样式,默认为raised

unadorned

{ yes | no | 1 | 0 | on | off }

默认为no

注意:dialogHide,edge,unadorned这三个属性是用在HTA(HTML Aplication)中的,一般网页上用不到。

参数传递

通过vArguments来传递参数,类型不限制,对于字符串类型,最大为4096个字符,也可以传递对象,例如:

a.html

var p = { Name: "Sunny D.D", Age: 25 };

window.showModalDialog("b.html", p);

b.html

alert(window.dialogArguments.Name);

当显示b.html页面时,会弹出对话框,内容为“Sunny D.D”。

返回值

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

a.html

window.showModalDialog("b.html");

alert(window.returnValue.Name);

b.html

var p = { Name: "Sunny D.D", Age: 25 };

window.returnValue = p;

当关闭b.html页面时,会弹出对话框,内容为“Sunny D.D”。

防止模态窗口打开新窗口

在页面的 <body>标签前加入<base target="_self">:

<head>

<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

<title>测试页</title>

<base target="_self" />

</head>

<body>

</body>

调用父窗口的属性或者方法

参数方式

因为vArguments参数的类型没有限制,所以可以将父窗体对象作为参数的一个属性传递至子窗体:

parent.htm

<script>

function show() {//父窗口的方法

alert("show");

}

var arg = new Object(); //传递进去的参数

arg.win = window; //把当前窗口的引用当参数传进去

arg.str = "argument"; //要传进去的其他参数

window.showModalDialog("son.htm", arg, 'help:no');

</script>

son.htm

<script>

var arg = window.dialogArguments;

alert(arg.str);

arg.win.show(); //调用父窗口的方法

</script>

window.parent方式

在子窗体中,可以使用语句window.parent来获取父窗体对象,从而调用父窗体的属性与方法:

parent.htm

<script>

function show() {//父窗口的方法

alert("show");

}

window.showModalDialog("son.htm");

</script>

son.htm

<script>

window.parent.show(); //调用父窗口的方法

</script>

window.showModalDialog基础的更多相关文章

  1. 让IE8在win7下面能显示使用window.showmodaldialog弹出窗口的地址状态栏

    问题来源:最近又要对老的系统进行改善,由于用到了window.showmodaldialog这个方法弹出窗口,比如从主界面弹出新增或者修改窗口,如下图所示,显示没有地址栏,进行代码修改还要找到相应的文 ...

  2. window.showModalDialog的简单实践

    Super.jsp - 父窗口 <%@ page language="java" import="java.util.*" pageEncoding=&q ...

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

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

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

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

  5. 关于window.showModalDialog的一些配置

    关于window.showModalDialog的一些配置 一.window.showModalDialog的滚动条 其实纵向滚动条很好去掉,难办的就是横向滚动条.在Firefox下如果window. ...

  6. window.open()&&window.showmodaldialog()

    open 打开一个新窗口,并装载URL指定的文档,或装载一个空白文档,如果没提供URL的话. 适用于 窗口 语法 window = object.open([URL[,name[,features[, ...

  7. JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作

    一.Iframe 篇 公共部分 //父对象得到子窗口的值 //ObjectID是窗口标识,ContentID是元素ID function GetValue(ObjectID,ContentID) { ...

  8. JS中window.showModalDialog()详解

    window.showModalDialog()方法用来创建一个显示HTML内容的模态对话框. window.showModelessDialog()方法用来创建一个显示HTML内容的非模态对话框.  ...

  9. 项目中用到的window.showModalDialog(来自网络)

    window.showModalDialog相关: showModalDialog() (IE 4+ 支持) showModelessDialog() (IE 5+ 支持) window.showMo ...

随机推荐

  1. crtbegin_dynamic.o: No such file: No such file or directory

    /homesec/android2/zhangbin/053work3/hi050src/HiSTBAndroidV400R001C00SPC050B012/prebuilt/linux-x86/to ...

  2. operator.itemgetter的用法【转】

    operator.itemgetter函数 operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),下面看例子. a = [,, ...

  3. poj 2762 Going from u to v or from v to u?

    题目描述:为了让他们的儿子变得更勇敢些,Jiajia和Wind将他们带到一个大洞穴中.洞穴中有n个房间,有一些单向的通道连接某些房间.每次,Wind选择两个房间x和y,要求他们的一个儿子从一个房间走到 ...

  4. 《C++ Primer 4th》读书笔记 第9章-顺序容器

    原创文章,转载请注明出处:http://www.cnblogs.com/DayByDay/p/3936460.html

  5. Delphi Waring 的信息

    Display PreferencesWarning messages (Delphi)Go Up to Delphi Compiler Directives (List) Index TypeSwi ...

  6. 也说Autofac在MVC的简单实践:破解在Controller构造函数中的实例化 - winhu

    相信大家对Autofac并不陌生,很多人都在使用.本文只是介绍一下本人在使用时的一点想法总结. 在使用一个框架时,肯定要去它的官网查阅一下.autofac的官网给出了一些经典的使用案例.如注册容器: ...

  7. Centos6.5下编译安装ACE6.0

    ACE在Linux下的编译安装步骤(CentOS6.5 64Bit) Linux平台安装(CentOS6.5 64bit) 1, 下载ACE软件包,上传至Linux服务器(假设目录为/opt/ace, ...

  8. hdu3231 (三重拓扑排序) 2009 Asia Wuhan Regional Contest Hosted by Wuhan University

    这道题算是我拓扑排序入门的收棺题了,卡了我好几天,期间分别犯了超时,内存溢出,理解WA,细节WA,格式WA…… 题目的意思大概是在一个三维坐标系中,有一大堆矩形,这些矩形的每条棱都与坐标轴平行. 这些 ...

  9. oracle返回多结果集

    kavy 原文 oracle返回多结果集 Oracle存储过程: create or replace procedure P_Sel_TopCount2(in_top in number, out_c ...

  10. Win10遇上Kindle就蓝屏

    在使用 Kindle 连接 Win10 时会出现蓝屏现象,现在,微软承认 Windows 10 插入 Kindle 导致蓝屏问题,并表示目前正着手制作补丁.微软表示:“我们承认确实存在当Kindle ...