模态窗口传值与非模态窗口传值

一、模态窗口传值

  1、父页面传给子页面

    父页面: var arg = {"win":window,"name":"WebForm1.aspx"}

        window.showModalDialog("WebForm2.aspx" , arg);

    子页面: var arg = window.dialogArguments;

        alert(arg.name);  //WebForm1.aspx

        arg.win.SayHello();  //调用父页面方法

  2、子页面回传给父页面

    子页面:  var returnArg = {"win":window,"name":"WebForm2.aspx"}

        window.returnValue = returnArg;

    父页面:  var theValue = showModalDialog("WebForm2.aspx" , arg);

        alert(theValue.name);  //WebForm2.aspx

        theValue.win.SayHello();  //调用子页面方法

二、非模态窗口传值

  1、父页面传给子页面

    父页面: var arg = {"win":window,"name":"WebForm1.aspx"}

        window.showModelessDialog("WebForm2.aspx" , arg);

    子页面: var arg = window.dialogArguments;

        alert(arg.name);  //WebForm1.aspx

        arg.win.SayHello();  //调用父页面方法

  2、子页面回传给父页面

    子页面:  var returnArg = {"win":window,"name":"WebForm2.aspx"}

        window.returnValue = returnArg;

    父页面:  var theValue = showModelessDialog("WebForm2.aspx" , arg);

        alert(theValue.name);  //WebForm2.aspx

        theValue.win.SayHello();  //调用子页面方法

原文地址:https://www.cnblogs.com/dengshaojun/p/3625199.html