2分钟通过javascript的opener方式实现调用父窗口方法示例

父窗口的JS代码:

// 打开上传文件窗口
function uploadImgFile(id){  
	// open里面的参数详情,查看MDN,更系统的详情资源
    window.open("${base}/ajax/picupload.action?parentImgUrlId="+id,"","height=300, width=500, toolbar =no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");  
    //document.getElementById(id).value = someValue;  
}  
  
// 此方法将会被子窗口调用
function testfun(params){  
    alert("来自子窗口的参数:"+params);  
}

子窗口JS代码:

使用window.open后的子窗口调用父窗口方法代码

// 调用父窗口方法
function setParentImgUrl(){  
    window.opener.testfun('children');  

    // 直接操作父窗口dom元素 如赋值
    // window.opener.document.getElementById("${parentImgUrlId}").value = document.getElementById('img_url').value;  
	// 关闭窗口
    window.close();  
}

你可能感兴趣的:(+Frontend,Practices/前端实战)