window.showModalDialog与opener及returnValue

首先来看看 window.showModalDialog 的参数

  1. vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures]) ;

sURL : 打开窗口的地址;

vArguments : 传递参数;

sFeatures : 窗口属性列表;

第一个参数是必须的, 后两个可以省略.

这里我们要利用的就是第二个参数. 原理是将父窗口的被控制对象以参数的形式传递到子窗口, 在子窗口中直接控制这个对象即可.

举例来说:

parent.html

<script type="text/javascript">

function openWin(){
// 子窗口地址

var srcFile = "child.html";

// 子窗口属性

var winFeatures = "dialogHeight:300px; dialogLeft:200px;";

// 将 From 的 ID 作为参数传递到子窗口

var obj = getForm;

// 打开子窗口

window.showModalDialog(srcFile, obj, winFeatures);

}

</script>

<form id="getForm"> 回传值:
<input id="getValue" type="text" />
</form>
<input onclick="openWin()" type="button" value="打开" />

 

child.html


<script type="text/javascript"><!--
function send(){

    // 获取参数传递的对象

    var obj = window.dialogArguments;
    // 控制对象

    obj.getValue.value = ‘from Child‘;
}

// --></script>

<a onclick="send();" href="#">Send</a>

 

运行 parent.html , 单击 [打开] 按钮弹出对话框, 点击 Send 链接将值传递到 parent 的文本框中.

 

传递的参数当然也可以是其他对象, 例如 window . 值得注意的是传递的是对象, 而不是字符串.

 

 

window.showModalDialog 打开的子窗口,不支持 window.opener 属性

获取父窗口,需要显示作为参数传入

// a.aspx

window.showModalDialog("b.aspx", window);

// b.aspx

var theOpener = window.dialogArguments;

theOpener.close();

// 对于内嵌 c.aspx ->

var outerOpener = window.top.dialogArguments;

outerOpener.close();

时间: 2024-07-30 23:32:10

window.showModalDialog与opener及returnValue的相关文章

window.open、window.showModalDialog和window.showModelessDialog 的区别

一.前言 要打开一个可以载入页面的子窗口有三种方法,分别是window.open.window.showModalDialog和window.showModelessDialog. open方法就是打开一个页面,可以说同用url链接打开一个页面一样,不推荐使用,因为很多浏览器会拦截. 这里推荐使用的是window.showModalDialog和window.showModelessDialog,下面介绍二者的异同和用法. 二. showModalDialog和showModelessDialo

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

父窗口打开子窗口页面: var fatherWindow = document.all.dealReason;//想传的值 win = window.showModalDialog(strUrl, fatherWindow, "dialogWidth=800px;dialogHeight=600px;"); //strUrl是子窗口页面,fatherWindow是想传的值,win是子窗口返回的值document.all.dealReason.value = win; 子窗口: var

window.showModalDialog 与window.open传递参数的不同?

简单的说,就是一个在弹出窗口之后可以做其它的事,即window.open 另一个在弹出窗口之后不能做其它的事,只能是关闭了当前的窗口之后才能做其它的事,即window.showModalDialog 那么两者在使用上有什么不同呢?他们分别是如何和父窗口进行交互的呢? 先来看window.showModalDialog的例子: 我这里现在有一个父窗体parent.jsp,它里面有一个方法 function openChild(){                var temp = window.

window.showModalDialog父子窗口参数传递

在开发过程中遇到window.showModalDialog()打开的模态对话框需要从子窗口传递返回值给父窗口中的某个插件,开始想通过window.opener得到,但是试了几次得不到,后来发现原来在当前打开窗口(子窗口)中可以通过window.returnValue=指定返回值;window.close();之后父窗口可以使用var result = window.showModalDialog(url,window,"dialogWidth=600px;dialogHeight=500px;

JS中window.showModalDialog()详解 HTML DOM open() 方法

window.showModalDialog()方法用来创建一个显示HTML内容的模态对话框. window.showModelessDialog()方法用来创建一个显示HTML内容的非模态对话框. 使用方法: vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures]) vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures

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

父页面处理: function ProductList() {   var TypeID = window.document.getElementById("Type").value;   var returnvalues = window.showModalDialog('ProductList.aspx?Type=' + TypeID,'window','dialogWidth=700px;dialogHeight=680px');    if(returnvalues!=unde

解决window.showModalDialog在Firefox无法支持

在网页程序中,有时我们会希望使用者按下按钮后开启一个保持在原窗口前方的子窗口,而在IE中,我们可以使用showModalDialog来达成,语法如下 : vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures]) 范例: window.showModalDialog("openwin.html","Arguments","dialogHeight: 200px; dial

window.open()和window.showModalDialog

零.window.open()和window.showModalDialog 本人在使用时主要实现如下个功能, 以对话框形式弹出画面,且要求对话框置顶,不可操作其他画面,并且关闭画面时刷新父页面. window.open 可实现以对话框形式弹出画面,并且关闭画面时刷新父页面.但"对话框置顶,不可操作其他画面"本人并未找到方法. //刷新父页面 Response.Write("<script>window.opener.location.href=window.op

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

父窗口 创建一个窗口 var backinfo = window.showModalDialog('UserSelect.aspx', '', 'dialogHeight=600px; dialogWidth= 600px; edge=Raised; center=Yes;resizable= No; status= no;help=no'); 子窗口 调用JS关闭自身并返回值 function SelectCompany(obj) {                            wi