龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > Javascript编程 >

window.showModalDialog 子窗口给父窗口赋值

时间:2012-12-29 08:41来源:未知 作者:admin 点击:
分享到:
今天在做一个客户的内容时,突然要从相册选择照片,这样我本来是用iframe来实现的,但是弹出我用的是window.showModalDialog用平常的window.parent获取不到值,以后从百度找到一个方法,现在
今天在做一个客户的内容时,突然要从相册选择照片,这样我本来是用iframe来实现的,但是弹出我用的是window.showModalDialog用平常的window.parent获取不到值,以后从百度找到一个方法,现在记录有一下以代碰到相同问题的朋友参考。

A.使用window.returnValue给父窗口传值,然后根据值判断是否刷新。

      在window.showModalDialog窗口页面中用window.returnValue方式设置返回值;
      比如:window.returnValue='refresh';
   
   B。在写window.showModalDialog弹出窗口函数时,定义个变量,然后根据变量值进行操作父窗口的操作;
   例如:var winPar=window.showModalDialog(urls,'ERPWINDOWS','dialogWidth='+widths+'px;dialogHeight='+heigths+'px;status=no;center=yes;scroll=no');
  if(winPar == "refresh")
       window.location.reload();//当window.showModalDialog窗口关闭时执行
         winPar为A步骤给showModalDialog窗口设置的返回值

  总结:由于window.showModalDialog函数打开一个IE的模式窗口(就是打开后不能操作父窗口,只能等模式窗口关闭时才能操作),
    
        所以想要刷新父窗口只能在模式窗口关闭后执行。用window.returnValue可以向父窗口传值,这样一来可以用从模式窗口向父窗口传递值,
window.showModalDialog 子窗口 给父窗口赋值 的使用方法
(1)
父窗口

 代码如下

<script language="JavaScript" type="text/javascript">
     function openwin() {
         var rsName = window.showModalDialog("RetailShopSelect.aspx", "newwindow", "dialogWidth:700px,dialogHeight:540px;center:Yes;resizable:no;status:no;scroll:no;")
         if (rsName != null && rsName != "") {
             var strs = new Array();
             strs = rsName.split(" ");
             window.document.getElementById("tbxRSId").value = strs[0];
             window.document.getElementById("tbxRSNameCn").value = strs[1];
         }
     }
</script>

<tr>
    <td>&nbsp;</td>
    <td class="style1">用 户 名</td>
    <td><asp:Label ID="lblUserCode" runat="server" ForeColor="Red"></asp:Label></td>
    <td class="style1">所 在 店</td>
    <td>
        <asp:TextBox ID="tbxRSNameCn" runat="server" Width="105px"></asp:TextBox>
      <asp:Button ID="btnSelectRetailShop" runat="server" Text="选择店面" OnClientClick="openwin()" Height="25px" Width="80px"/>
      <input type="hidden" ID="tbxRSId" value="" runat="server"/></td>
    <td>&nbsp;</td>
</tr>


 

子窗口
<base target="_self" />   ------加上这一句话可以在子窗口进行一些操作,要是不加的话,比如查询会另弹出一个页面来

 代码如下

<script type="text/javascript">
    function ReKey(rsName)//页面间传值
   {
       window.returnValue = rsName;
       window.close();
   }
</script>

<asp:TemplateField>
<HeaderTemplate>
<div style="font-size:12px">确认选择</div>
</HeaderTemplate>
<ItemTemplate>
<div align="center" style="font-size:12px"><a onclick='javascript:ReKey("<%#Eval("id")%> <%#Eval("NameCn")%>")'>
<input id="Button1" class="BigInput" type="button" value="确认选择" /></a> </div>
</ItemTemplate>
</asp:TemplateField>


精彩图集

赞助商链接