zoukankan      html  css  js  c++  java
  • 在ModalDialog中操作父窗口对象

    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代码如下

    b.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();

    }

    }

  • 相关阅读:
    运维必备:Oracle自备份精简教程(linux及win)
    Ansible11:变量详解【转】
    Ansible10:Playbook的角色与包含【转】
    Nginx下Redmine配置
    centos 6.5下安装mysql+nginx+redmine 3.1.0 笔记
    nginx 出现413 Request Entity Too Large问题的解决方法
    linux 安装redmine 遇到的问题
    linux编译ruby1.8.7 出现OPENSSL错误
    Linux下安装项目管理工具Redmine
    (转载)Go语言开发环境配置
  • 原文地址:https://www.cnblogs.com/rash/p/2672925.html
Copyright © 2011-2022 走看看