1、不能使用window.parent
Window.parent是用来在frame中进行操作的,在对话框中不能用来操作父窗口对象
2、正确的做法
调用modaldialog时通过传参数的方式操作
例:
需求
父窗口页面为a.html 子窗口页面为b.html。a.html中有文本框id为test1,在打开的对话框中点击按钮,将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>
传的是个文本框,也可以传整个父类窗口window
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”的的form,form中有id为test2的文本框,在b.html中,除了进行上面的操作之外,还要将test2的值改为“子窗口值2”,并将form提交到c.html。
实现1
将a.html中打开对话框的函数改为如下方式:
window.showModalDialog("b.html", window.document);
将b.html中func1()改为如下:
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.html中func1()改为如下:
function func1(){
var pwin = window.dialogArguments;
if(pwin!=undefined){
var codeStr = "func();"
pwin.execScript(codeStr,"javascript");
window.close();
}
}
分享到:
相关推荐
在ModalDialog中操作父窗口对象 1、不能使用window.parent Window.parent是用来在frame中进行操作的,在对话框中不能用来操作父窗口对象 2、正确的做法 调用modaldialog时通过传参数的方式操作 例: 需求 父窗口页面...
jquery.modaldialog.1.0.0.zip_JQuery模式窗体例子
modalDialog 弹出框 提示框,确认框。...弹出框里面的dom元素如果有data-id属性值,则相当于绑定了click事件,事件的回调函数名为传给ModalDialog的options对象中key等于data-id的值所对应的value。 加载弹框样
Modal Dialog Box in Embedded YouTube Video
How to update a modal dialog contents using a callback function(17KB)
一个想当漂亮的jquery提示框:jQuery Modal Dialog弹出对话框插件,可用它实现各种的网页提示效果,比如错误提示框、警告框、操作提示框等,暖色调界面,使用方法简单,参考本例所展示的各种提示框生成办法,就可...
一个支持ff的modaldialog的js代码
NULL 博文链接:https://call-me-java-126-com.iteye.com/blog/1722179
非常好用的jquery弹出对话框
WPF 弹出框
这里,`parent` 是可选的,表示对话框的父窗口。 2. **设置对话框的标题和内容:** ```cpp dialog->setWindowTitle("Modal Dialog Example"); QLabel *label = new QLabel("This is a modal dialog.", dialog...
For instance using "Localization package" from the asset store you would do this: MessageBox.Localize = (originalString) => { return Language.Get(originalString); }; Current text strings that need to...
控件使用说明,大家赶紧下载看看吧,这些还不够吗?
modaldialog.js modaldialog.js基于jQuery开发的插件。 Feature 支持多弹出层 兼容主流浏览器,包括IE6 Demo $("#btn").click(function(){ var dialog = new Dialog({ content:"<p>Hello, world</p>" }); }); $...
$.modalDialog2.xxx 这个xxx是可以自己定义名称,主要用在弹窗关闭时,刷新某些对象的操作,可以将xxx这个对象预定义好 代码如下: $.modalDialogTwo = function(options) { if ($.modalDialogTwo.handler == ...
先决条件您需要在计算机上正确安装以下物品。 (带有NPM)安装git clone 此存储库切换到新目录npm install bower install运行/开发ember server 访问您的应用程序,为 。代码生成器利用许多代码生成器,尝试使用...
可以在子窗口中通过设置window.returnValue的值,让父窗口可以获取这个returnvalue. 2.一个例子1)主窗口main.html,2)在主窗口中通过showModalDialog的方式打开子窗口sub.html3)在子窗口中设置returnValue返回给主...
父窗口:parent 弹出窗口:modal 弹出窗口与父窗口互相交换数据
通常使用window.open的方式开启新窗口的话 要取得父窗口的控件,可以用window.opener来取得父窗口 然而如果使用showModalDialog的话…却无效 如果有需要的话,需要修改开启的语法以及showModalDialog中的语法 开启...