首先写一个botton按钮 id为addImg 然后点击打开弹窗
$("#addImg").click(function(){
var url="弹窗地址";
var wins=window.open(url,'命名','height='700',width='700' scrollbars=yes,)
wins.focus();
});
然后在对应的弹窗里面写一个botton按钮 id为imgbutton然后点击处理完数据之后返回用
window.opener.postMessage(数据,"*");
(注)是要用window的postMessage数据 跟后续接收回调数据的message相互对应
然后关闭窗口
$("#imgbutton").click(function(){
$.ajax({
type: "post",
url:"后端地址",
cache: false,
processData: false,
contentType: false,
dataType:'json',
data: ,
success:function(data){
if(data.status=="1"){
//*是指全部窗口
window.opener.postMessage(JSON.stringify({"data":data,"status":"1","method":""}),'*');
window.close();
return;
}
}
})
})
当弹窗处理完数据之后我们在打开弹窗的js里再接收数据 进行处理数据
注(是message)
window.addEventListener('message', function(event) {
console.log('弹窗已关闭');
var data ;
try {data=JSON.parse(event.data);} catch (e) {}
//data就是弹窗传过来的数据就可以使用了
});