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

showModalDialog使用

阅读更多
                                                    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
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="icyheart";
         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", obj, "dialogWidth=200px;dialogHeight=100px");
         alert(str);
</script>
modal.htm
<script>
         window.returnValue="http://leo1211.iteye.com/";
</script>

 

---------------------------------------------------------------------------------------------------------------------------------

Firefox 3.0 已经支持window.showModalDialog了,平时很多地方用模态对话框还是很方便的,

下面一个例子,传一个CallBack过去,让子窗口可以调用父窗口的方法。

父窗口:

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function ShowDialog()
{
    var param = "dialogWidth:400px;dialogHeight:300px;scroll:no;status:no;resizable:no";
    return window.showModalDialog("pop.html", GetResult, param);
}

function GetResult(ret)
{
    alert(ret);
    document.getElementById("tbTest").value = ret;
}
//-->
</SCRIPT>
<input type="button" value="Pop" onclick="ShowDialog();" />
<input type="text" id="tbTest" />
</BODY>
</HTML>

 

子窗口:

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function SetValue()
{
    var callBack = window.dialogArguments;
    if (callBack != undefined && callBack != null)
    {
        callBack(Math.random());
    }
}
//-->
</SCRIPT>
<input type="button" value="SetValue" onclick="SetValue();" />
</BODY>
</HTML>

 

子窗口可以调用父窗口的alert,以及js赋值等,当然就可以ajax了。

不过貌似不能让父窗口提交。这点倒是有点麻烦。可以用ajax处理父窗口的数据提交。

 

 

 问题解决:

1.子窗体不刷新,总弹出新窗口?

在子窗体应用的文件的head区之间添加代码: 
<base target="_self"> 

这样在打开的子窗体中的链接仍然会在子窗体刷新,而不会跑到新窗口。

 

 

 

 

 

 

分享到:
评论

相关推荐

    Window.ShowModalDialog使用手册

    下面是一些使用`showModalDialog()`的示例: ```javascript // 基本用法,打开一个HTML文件 var result = window.showModalDialog("dialog.html"); // 传递参数 var result = window.showModalDialog("dialog....

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

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

    showModalDialog使用例子,父窗口向子窗口传递值,子窗口设置父窗口的值,子窗口关闭的时候返回值到父窗口

    让我们深入探讨一下`showModalDialog`的使用方法及其相关知识点。 首先,`showModalDialog`的基本语法如下: ```javascript var returnValue = window.showModalDialog(url, arguments, features); ``` - `url`:...

    window.showModalDialog使用手册

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

    showModalDialog参数使用详解

    本篇文章将深入探讨`showModalDialog`的参数使用,以及如何在子父窗口之间传递数据。 `showModalDialog`函数的基本语法如下: ```javascript window.showModalDialog(url, [startNode], [features]); ``` - `url`...

    showModalDialog和showModelessDialog使用心得

    ### showModalDialog和showModelessDialog使用心得:深入解析与实践 在Web开发中,`showModalDialog` 和 `showModelessDialog` 是两种用于创建弹出窗口的方法,它们各自具有独特的特性和应用场景。本文将详细解析这...

    浅谈JavaScript窗体Window.ShowModalDialog使用

    `window.showModalDialog()`的基本使用方法如下: ```javascript vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures]) ``` 参数解释如下: 1. `sURL`(必需):字符串类型,用于指定...

    使用selenium测试showModalDialog模态对话框

    在自动化测试领域,Selenium 是一个广泛使用的工具,它允许测试人员通过编写代码来模拟用户在Web应用程序上的交互。然而,对于某些特定的功能,比如 Internet Explorer 中的 `showModalDialog` 方法,Selenium 存在...

    解决window.showModalDialog跨域返回值

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

    showModalDialog()、showModelessDialog()方法的使用.

    在Web开发中,有时我们...需要注意的是,这两个方法在现代浏览器中支持度有限,尤其是跨浏览器兼容性问题,因此在新的项目中可能会考虑使用更通用的解决方案,如Bootstrap的模态框或者其他前端框架提供的对话框组件。

    window.showModalDialog方法的使用

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

    showModalDialog

    下面将详细介绍`showModalDialog`的使用、功能、优缺点以及相关的HTML和JavaScript知识。 `showModalDialog`的基本语法如下: ```javascript window.showModalDialog(url, [startValue], [features]); ``` 1. `...

    showModalDialog技术文章

    这篇名为"showModalDialog技术文章"的博客文章可能详细介绍了这个API的使用方法、优缺点以及一些实际应用场景。 `showModalDialog`函数在JavaScript中被用来创建一个阻塞式的对话窗口,这意味着用户必须与对话框...

    javascript showModalDialog模态对话框使用说明

    1. 标准的方法 代码如下: [removed] function openWin(src, width, height, showScroll){ window.showModalDialog (src,””,”location:No;status:No;help:No;dialogWidth:”+width+”;dialogHeight:”+height+”;...

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

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

    如何使用showModalDialog

    本篇文章将深入探讨`showModalDialog`的使用方法、参数、返回值以及它在现代Web开发中的地位。 `showModalDialog`的基本语法如下: ```javascript window.showModalDialog(url, windowObject, features); ``` 1. ...

    showModalDialog参数传递和获

    由于`showModalDialog`不支持最新的Web标准,存在许多问题,如不兼容性(主要在IE浏览器中使用)、无法进行CSS3和JavaScript增强以及阻塞主线程等。因此,现代Web开发通常使用更灵活的替代方案,如`&lt;dialog&gt;`元素、...

    showModalDialog跨域解决例子

    然而,当尝试使用`showModalDialog`在不同源之间打开页面时,同样会遭遇跨域限制。标题"showModalDialog跨域解决例子"表明我们将探讨如何克服这个限制。 首先,理解跨域的原理至关重要。同源策略是浏览器为了安全而...

Global site tag (gtag.js) - Google Analytics