javascript父窗口与子窗口通信

在父窗口的js代码

//回调的函数  
function alt(temp){ alert(temp); }; $("#Btn").click(function (obj) { //声明子窗口触发的方法; window.returnCallBackValue354865588 = alt; //打开新的窗口 window.open(str, "roleSelect", 'height=300,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizeable=no,location=no,status=no'); });

  子窗口的js代码:

//子窗口的按钮 点击之后关闭当前子窗口页面,并到打开的父页面中触发绑定的回调方法;

  $("#submitBtn").click(function () {
//第二个参数是要返回的数据。 window.opener.returnCallBackValue354865588.call(window.opener, "qwe"); window.close(); });

  在chrome下测试 可以使用,ie下可以使用showModalDialog方法。

There are two ways of constructing a software design.One is to make it so simple that there are obviously no deficiencies;the other is to make it so complicated that there are no obvious deficiencies.
原文地址:https://www.cnblogs.com/yuanjunqq/p/6029308.html