js 弹出子窗口后,设定为最顶层焦点,关闭后传参给父窗口(兼容其它浏览器)

父窗口

JS

<script type="text/javascript"> 
function OpenDialogPageForFckEdit(ObjPage)
 { 
//判断是否IE浏览器 
 if (navigator.appVersion.indexOf("MSIE") == -1) 
     { window.open(ObjPage + '?typeIe=XE', 'newWin', 'width=630,height=420,top=80,left=300,resizable=no,scrollbars=no');
       return 
     } else
     { 
      var GetValue = showModalDialog(ObjPage + '?typeIe=IE', '', 'dialogWidth:630px;dialogHeight:420px;dialogLeft:300;dialogTop:80;scroll:no;'); 
      if (GetValue != null)
          { document.getElementById("<%=txt_ItemID.ClientID %>").value=GetValue; 
          } 
     } 
  }
function SubfromPop() 
{
document.getElementById("<%=txt_ItemID.ClientID %>").value=document.getElementById("Text_VendorId").value; 
} 
</script>


 调用: 
 

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="OpenDialogPageForFckEdit('Default.aspx')" />

子窗口:

js :

<script type="text/javascript">
//关闭时传参数处理      
function foo()
{
if(getUrlParam("typeIe")=="IE")
    {
     window.returnValue=document.getElementById("<%=txt_Vendor.ClientID %>").value;
     window.close();
    }else
     {
      window.close();
      window.opener.document.getElementById("Text_VendorId").value=document.getElementById("<%=txt_Vendor.ClientID %>").value;
      window.opener.SubfromPop();
     }
}
//JS 处理Request 参数
function getUrlParam(name)
     {      
          var reg = new   RegExp("(^|&)"+   name   +"=([^&]*)(&|$)");      
          var r = window.location.search.substr(1).match(reg);      
          if (r!=null) return  unescape(r[2]); return  null;      
      }
</script>
调用:

 <div>
        <asp:TextBox ID="txt_Vendor" runat="server"></asp:TextBox>
        <input id="Button2" type="button" value="button" onclick="return foo();" />
    </div>



你可能感兴趣的:(浏览器,function,null,button,scroll,textbox)