window.opener返回值的用法

1.父窗体 代码
   <input  type="button" visible="false"  id="Button1" class="btn" value="点此添加照片" onclick="javascript:ontc_small();" />

  js  代码如下:


    function ontc_small(){
    
    var url='pic.aspx?filepath=small&txtpath=image_small&imgpath=img_small';
   
    window.open(url,'newwindow','height=400,width=600,top=100,left=100,scrollbars')
    
    }

2. 子窗体代码如下



function winBack()
{
       if(window.opener) {
       var v=$("#imgCropped").attr("src");
             fWindowText1 = window.opener.document.getElementById('<%=txtpath %>');
              fWindowText1.value = v;
              fWindowText2 = window.opener.document.getElementById("<%=imgpath %>");
              fWindowText2.src=v;
             
             
              window.close();
       }
}

说明:  fWindowText1 = window.opener.document.getElementById('<%=txtpath %>');

 其中 <%=txtpath %>  是父窗体中的的控件id,这样子窗体的参数就可以赋值给父窗体的控件了

原文地址:https://www.cnblogs.com/tiancai/p/2413204.html