`
高军威
  • 浏览: 183113 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Window.ShowModalDialog使用手册

js 
阅读更多
基本介绍:
         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
<script>
         var obj = new Object();
         obj.name="51js";
         window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");
</script>
modal.htm
<script>
         var obj = window.dialogArguments
         alert("您传递的参数为:" + obj.name)
</script>
-------------------------------
2.   可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例如:
------------------------------
parent.htm
<script>
         str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");
         alert(str);
</script>
modal.htm
<script>
         window.returnValue="http://homepage.yesky.com";
</script>





1、基本知识 

showModalDialog() (IE 4+ 支持)
showModelessDialog() (IE 5+ 支持)
window.showModalDialog()方法用来创建一个显示HTML内容的模态对话框。
window.showModelessDialog()方法用来创建一个显示HTML内容的非模态对话框。


    2、使用方法 vReturnValue=window.showModalDialog(sURL[,vArguments][,sFeatures]);
vReturnValue=window.showModelessDialog(sURL[,vArguments][,sFeatures]); 


    3、参数说明  参数名称  性质  类型  作用
sURL  必选  字符串  用来指定对话框要显示的网页的URL。
vArguments  可选  变体  用来向对话框传递参数。参数类型不限。
对话框通过window.dialogArguments来取得传递进来的参数。
sFeatures  可选  字符串  用来描述对话框的外观等信息

    4、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)中的,一般网页上用不到。


    5、参数传递 通过vArguments来传递参数,类型不限制,对于字符串类型,最大为4096个字符,也可以传递对象,例如: parent.htm
<script>
window.showModalDialog("sun.htm","传递进去的参数","help:no;scroll:no");
</script>
sun.htm
<script>
alert("传来的参数:" + window.dialogArguments);
</script> 


    6、返回值 通过window.returnValue向打开对话框的窗口返回信息,也可以是对象。例如: parent.htm
<script>
result=window.showModalDialog("son.htm","","help:no;scroll:no");
alert(result);
</script>
son.htm
<script>
window.returnValue="这里存放返回的结果";
</script> 


    7、防止在模态窗口中提交后新开一窗口
   在页面的 <body>前加入<base target="_self">

    8、调用父窗口的方法同时传递参数 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> 


例子:
<html>
<head>
<title>showModalDialog</title>
<script language="JavaScript">
//aInfo作为数组对象,将被showModalDialog传递到子页面(或叫模式窗体,指当显示页面未关闭前,不能对父页面操作)
//也可用var oMyobject=new Object();
//oMyobject.firstProperty = value; oMyobject.lastProperty = value;的方式定义一个对象(firstProperty,lastProperty是自己按需定义的对象属性,可是任意取名并赋值)
var aInfo  = new Array(3);
aInfo[0] = "aaaaaaaaaaa";
aInfo[1] = "bbbbbbbbbbb";
aInfo[2] = "ccccccccccc";
var url = "dialog.html";
var sFeatures = "width=500px;height=500px;edge=sunken";


function gg(){
 //弹出一个showModalDialog,并以returnValue来获取返回值
 var returnValue = window.showModalDialog(url,aInfo,sFeatures);
 if(returnValue!=null){
  alert(returnValue);
 }  
}
</script>
</head>

<body>
<h3><input type="button" onClick="gg();" value="打开Dialog窗口"></h3>
<div ></div>
</body>
</html>


<html>
<head>
<title>Dialog</title>
<script language="JavaScript">
<!--
//获取父窗口传来的对象(本例中就是父页面中的“oInfo”数组对象,也可用“window”对象,以便对父页面进行操作。总之,只要是object类型就成。)
var args = window.dialogArguments;//获取父页面传递过来的值;
if(args!=null){
 //document.write(args);
 for(var i=0;i<args.length;i++){
  document.writeln(args[i]+" "+(i+1));
 }
}else{
 alert("对不起,参数为空");
}

function hh(){
	var names = document.getElementById("names").value;
	window.returnValue = names;
	this.window.close();
}
//向父窗口返回的值
//-->
</script>
</head>

<body>
	<input type="text" id="names" name="names"/>
	<input type="button" onClick="hh();" value="测试"/>
</body>
</html>


但还是推荐大家用jquery,因为他很强大!各种效果!!
分享到:
评论

相关推荐

    window.showModalDialog模式对话框和 window.open的区别

    `window.showModalDialog` 和 `window.open` 都是JavaScript提供的两种打开新窗口的方法,但它们在功能和使用场景上有着显著的区别。 首先,我们来详细探讨`window.showModalDialog`。`showModalDialog`方法用于...

    Window.ShowModalDialog使用手册_对话框 .txt

    ### Window.ShowModalDialog 使用手册详解 #### 一、概述 `Window.ShowModalDialog` 是一个在 Internet Explorer 浏览器中特有的方法,用于创建模态对话框。此方法允许开发者在一个新的窗口中打开一个HTML页面,...

    解决window.showModalDialog跨域返回值

    1. 使用`window.showModalDialog`打开一个包含`iframe`的页面,`iframe`加载目标站点。 2. 目标站点通过修改`iframe`的`src`属性或提交表单等方式与主页面通信。 3. 主页面通过URL参数接收目标站点返回的值,并关闭`...

    window.showModalDialog以及window.open用法简介

    Window.showModalDialog 和 Window.open 用法简介 Window.showModalDialog 和 Window.open 都是 JavaScript 中的方法,用于创建新窗口或对话框,下面分别介绍它们的用法和参数。 一、Window.open() 方法 Window....

    针对window.showmodaldialog弹出窗体无刷新的详细使用

    本文将详细介绍`window.showModalDialog`的使用方法及其相关知识点。 1. **基本语法** `window.showModalDialog` 的基本调用形式如下: ```javascript var returnValue = window.showModalDialog(url, window, ...

    google不支持window.showModalDialog问题解决方案

    This is a `window.showModalDialog()` shim using a modal HTML5 `&lt;dialog&gt;` element and ECMAScript 6 Generators. It was tested in the latest Google Chrome with the *Enable Experimental JavaScript* flag ...

    JS 弹出对话框window.showModalDialog()

    ### JS弹出对话框 `window.showModalDialog()` 的使用与详解 #### 一、`window.showModalDialog()` 概述 在JavaScript中,`window.showModalDialog()` 是一个非标准但广泛使用的API,用于创建模态对话框。模态...

    window.showModalDialog方法的使用

    下面我们将详细探讨`window.showModalDialog`的使用及其相关知识点。 首先,`window.showModalDialog`的基本语法如下: ```javascript var returnValue = window.showModalDialog(url, [dialogArguments], ...

    window.showModalDialog(javascript)

    本文将重点介绍模态对话框的使用方法`window.showModalDialog()`。 模态对话框是一种阻止用户与网页其他部分互动,直到关闭对话框为止的交互方式。`window.showModalDialog()`是Internet Explorer 4及更高版本支持...

    父子窗口传值window.showModalDialog以及window.open用法简介

    window.showModalDialog以及window.open用法简介

    window.showModalDialog的基本用法

    ### window.showModalDialog 的基本用法 `window.showModalDialog` 是一个早期的浏览器功能,主要在 Internet Explorer(IE)4.0 及以上版本中支持。它用于打开一个新的模态对话框窗口,并且该窗口将阻止用户与主...

    window.showModalDialog使用手册

    **Window.showModalDialog 使用手册** `window.showModalDialog` 是Internet Explorer 4+ 版本开始支持的一个方法,用于创建一个模态对话框,显示HTML内容。模态对话框意味着用户必须关闭对话框才能继续与主窗口...

    关于struts2里用javascript刷新window.showModalDialog的父页面

    - **安全性考虑**:使用`window.showModalDialog`时需要注意防止XSS攻击等问题。 - **性能优化**:频繁地刷新页面可能会导致性能下降,建议优化数据处理逻辑减少不必要的刷新。 #### 总结 通过以上步骤,我们可以...

    window.showModalDialog打开跨域的页面并取到返回值

    主页面用window.showModalDialog的时候,如果直接打开其它系统的页面,这时候别人的页面在window.returnValue=1;这样返回值的时候,主页面是取不到返回值的,原因就是因为跨域了.

    window.showModalDialog的一个domo模型

    `window.showModalDialog` 是一个在JavaScript中用于打开模态对话框的函数,它在Web开发中被广泛使用,特别是在创建自定义对话框时。在这个示例中,我们有一个名为"TestWindowDialog"的压缩包文件,其中包含了实现`...

    ShowModalDialog与window.open的区别

    通过 `ShowModalDialog` 打开的窗口可以使用 `window.returnValue` 设置返回值。当对话框关闭时,这个值将被传递给调用 `ShowModalDialog` 的函数。 #### 五、示例代码 下面是一个简单的示例,展示了如何使用 `...

Global site tag (gtag.js) - Google Analytics