父页面代码

function alert_page(id)
{
  var k = window.showModalDialog("PicAdd.aspx?uid=<%=uid%>&filetype=1&temp=<%=temp %>",window,"dialogWidth:500px;dialogHeight:500px;help:no;maximize:no;minimize:no;scroll:aotu;status:no;resizable:no");
  alert(k);
  if(k!=null) document.getElementById(id).src=k;
}子页面代码function retval()
{
window.returnValue="asdasdasd"; //设置了返回值
window.close();//该页关闭时,该值才会返回
}结果alert(k) 为undefined   愁死我了   到底是怎么回事啊  高手解答!

解决方案 »

  1.   

    PicAdd.aspx ,触发了retval()没有?
      

  2.   

    function alert_page函数中的window.showModalDialog方法有问题,在js中是不能用'<%= >'这种表现方式的,你可以在页面中定义两个隐藏域来存储uid和temp,然后在js中通过getElementById()来获取,再加入window.showModalDialog方法中就可以了。
      

  3.   

    子页面代码
    <script>
    function retval(e){
      window.returnValue="asdasdasd";
    }
    </script><body onbeforeunload='retval(event);'>
      

  4.   

    window中没有returnValue属性,window.event中有这个属性
      

  5.   

    在子页面 上 应该改变 作为传进来的 window的值,而子页代码 的window 指的是 子页的窗口, 在子页面上应该使用 window.dialogArguments 
      

  6.   

    我用你的代码测试返回了结果“asdasdasd”.
    弱弱的问一句,你是不是忘记写body的事件了
    <body onunload='retval()'>
      

  7.   

    测试没有问题,应该是关闭页面时方法retval()没有调用
      

  8.   

    正解,使用dialogArguments而不是returnValue
      

  9.   

    a.html<html>
    <body>
    <script>
    function alert_page(id)
    {
          var k = window.showModalDialog("b.html",window,"dialogWidth:500px;dialogHeight:500px;help:no;maximize:no;minimize:no;scroll:aotu;status:no;resizable:no");      if(k){ document.getElementById(id).innerHTML=k;}
          else{      alert(k);}
    }
    </script>
    <input type='button' value='click me' onclick='alert_page("div")' />
    <div id='div'></div>
    </body>
    </html>
    b.html<html>
    <body>
    <script>
    function retval()
    {
    window.returnValue="asdasdasd"; //设置了返回值
    window.close();//该页关闭时,该值才会返回
    }</script>
    <input type='button' value='close' onclick='retval();' />
    </body>
    </html>
      

  10.   


    returnValue 在这里是正确的
      

  11.   

    <a href="javascript:window.opener=null;window.open('','_self');window.close();window.returnValue='1';">关闭</a>
    你确定关闭的时候触发了那个方法了。如果是直接按窗口右上角自带的关闭的话,不会触发你那个方法的。
      

  12.   

    其實有時也和瀏覽器有關係的,如果是ie的話可能沒問題,在firefox就有問題了,要考慮兼容瀏覽器!
    我有一個類似的可供參考!我的是從子頁面的下拉框返回值到父頁面的一個文本框裡.
    父頁面代碼:
       <script type="text/javascript" language="javascript">
        function doInput()
    {
     if(document.getElementById("txtUnit").value!="")
     {
     var unitid = document.getElementById("txtUnit").value;
     var win = window.showModalDialog("tmep/getLot.aspx?unitid="+unitid,window,"dialogWidth=300px;dialogHeight=100px;center=yes;status=no");
     if(win != null)
     {
      document.getElementById("txtLot").value = win;
     }
     }
    }
    </script><script language="javascript" type="text/javascript" > 
        function doPassToParent()
    { window.returnValue = document.getElementById("DropDownList1").value;
     window.close();
    }
    </script> 
      

  13.   

    子頁面html;
    <body>
        <form id="form1" runat="server">
        <center>
        <div>
          <table  cellpadding="0" cellspacing="0" border = "1">
            <tr>
              <td>工單:</td>
               <td><asp:DropDownList ID="DropDownList1" runat="server">
              </asp:DropDownList></td>
            </tr>
            <tr>
              <td colspan="2"><a href="javascript:doPassToParent();">確定</a>&nbsp;<a href="javascript:window.close();">關閉</a></td>
            </tr>
          </table>
         
        </div>
        </center>
        </form>
    </body>
      

  14.   

    已经解决了  因为两个页面分别在两个二级域名下  加上document.domain 就好了