Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > ASP > 在ModalDialog中操作父窗口对象
【标  题】:在ModalDialog中操作父窗口对象
【关键字】:ModalDialog
【来  源】:http://blog.csdn.net/Rayfly/archive/2006/06/07/777901.aspx

在ModalDialog中操作父窗口对象

Your Ad Here

 ModalDialog中操作父窗口对象

1、不能使用window.parent

Window.parent是用来在frame中进行操作的,在对话框中不能用来操作父窗口对象

2、正确的做法

调用modaldialog时通过传参数的方式操作

例:

需求

父窗口页面为a.html 子窗口页面为b.htmla.html中有文本框idtest1,在打开的对话框中点击按钮,将a.html的文本框值改为“子窗口值”。

实现

打开对话框时把test1作为参数传给子窗口,在子窗口中获取参数,将参数对象(即a.html中传过来的text对象)的value属性值设置为“子窗口值”

注意:这里只能传id,不能传name

 

a.html代码如下

<html>

<head>

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

<title>a.html</title>

</head>

<body>

<input type=text id=test1 value=''>

<input type=button value=" OK " onclick='window.showModalDialog("b.html", test1)'>

</body>

</html>

 

b.html代码如下

 

<html>

<head>

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

<title>b.html</title>

<script language=javascript>

function func1(){

//获取父窗口传过来的参数

var ptextid = window.dialogArguments;

if(ptextid != undefined){

//将父窗口传过来的对象的值改为“子窗口值”

ptextid.value = "子窗口值";

//关闭子窗口

window.close();

}

}

</script>

</head>

<body>

<input type=button value=" OK " onclick=func1()>

</body>

</html>

 

 

如果需要操作的父窗口对象比较多,也可以将window或window.document作为参数传给子窗口。

例:

需求

a.html中添加id为“aform”的的formform中有idtest2的文本框,在b.html中,除了进行上面的操作之外,还要将test2的值改为“子窗口值2”,并将form提交到c.html

实现1

a.html中打开对话框的函数改为如下方式:

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

 

b.htmlfunc1()改为如下:

 

function func1(){

var pdoc = window.dialogArguments;

if(pdoc!=undefined){

pdoc.all.test1.value="子窗口值";

pdoc.all.test2.value="子窗口值2";

pdoc.all.aform.action="c.html";

pdoc.all.aform.submit();

}

}

 

 

实现2

因为在子窗口中对父窗口进行的操作比较多,也可以采用execScript的方式实现。

 

a.html中打开对话框的函数改为如下方式:

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

 

添加javascript函数如下

function func(){

test1.value="子窗口值";

document.all.test2.value="子窗口值2";

aform.action="c.html";

aform.submit();

}

 

b.htmlfunc1()改为如下:

 

function func1(){

var pwin = window.dialogArguments;

if(pwin!=undefined){

var codeStr = "func();"

pwin.execScript(codeStr,"javascript");

window.close();

}

}

 

文/Ray

动态创建并关绑定到GridView中:【上一篇】
为什么选择Coldfusion:【下一篇】
【相关文章】
  • JS——showModalDialog()和showModelessDialog()使用方法
  • 网页中用showModalDialog打开子窗体,并返回参数的方法
  • Tip:Asp.net & ShowModalDialog
  • showModalDialog和showModelessDialog使用心得(转)
  • showModalDialog和showModelessDialog使用心得
  • showModalDialog()、showModelessDialog()方法使用详解
  • ShowModalDialog的具体用法
  • 【随机文章】
  • 笔记--1
  • Photoshop常见问题之专家会诊
  • Twelve Steps to Configuring Your Tsm Environment
  • [javascript]万年历
  • 《狮子王》收录!《王国之心2》新画面
  • [Apache完全安装指南]
  • 考试成绩的处理
  • 在程序中模拟BackSpace按键
  • 在线人数统计源代码
  • 轻松学会入侵网络服务器(2)
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.