zoukankan      html  css  js  c++  java
  • 【转】关闭模态子窗口后刷新父窗口

    在html里调用如下

    函数打开窗口  
      function   openaddcalendar()  
      {  
      var   width=210;  
      var   height=180;  
      var   surl='../openwindow.aspx?url=calendar.aspx';  
      var   returnVal;  
      returnVal=window.showModalDialog   (surl   +   '&width='   +   width   +'&height='+   height   ,'','dialogWidth='   +   width   +   'px;dialogHeight='   +   height   +   'px;resizable=no;help=no;center=yes;status=no;scroll=no;edge=sunken');  
      if   (returnVal=="True")  
      {  
      window.location.href=window.location.href;  
      window.location.reload;  
      }  
      }  
      如果需要判断是否刷新父窗口,就判断这个返回值,  
      这个返回值returnVal需要从模态窗口中返回  
        也就是用户点击模态窗口中的“关闭按钮”(一个button而不是右上角的"X")时  
                              Response.Write("<script   language=javascript>")  
                              Response.Write("window.returnValue='True';window.close()")  
                              Response.Write("</script>")  
      当然,如果用户直接点“X”来关闭窗口,就没法刷新了  
       
      如果不需要判断,就直接  
      window.location.href=window.location.href;  
      window.location.reload;  
      好了

    --------------------------------------------------------------

    最近做物资系统的时候,又涉及到模态窗口的问题了,上次做的时候没遇到这次这么多东西,记下来吧
    父窗口 js方法
    function openwin(id){  
        var answer=window.showModalDialog("demand.do?method=queryBOM&mdid="+id+"&d="+escape(new Date()),window.self,"dialogWidth:700px;dialogHeight:620px:center:yes");  
        if(answer==1){
         window.location.href = "demand.do?method=selmd&d="+escape(new Date()); //转到处理页面
         //window.location.reload();       刷新父窗口
         //winow.location.reload(true);
        
        }
    }
    加个escape(new Date()) 避免读取缓存,当然也可以在子窗口中,加入
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    子窗口 js 方法:
    function   reVal(){
        window.returnValue=1;   //父窗口中 answer的值
          window.close();
        }  
    打开模态窗口之后,父窗口会一直等待子窗口返回个值,如果是表单提交或是button就执行reVal()方法
    返回answer的值,window.returnValue=1 这个地方我测试了 好像只能返回String类型的,数组类型的不好使

    在子窗口中使用   window.opener.location.reload(); 不好使,不试用于模态窗口,window.opern() 好使

    还有个问题是:在模态窗口里form 提交会弹出新窗口,这个问题简单就在<head>里面加个<base target="_self">
    就可以搞定,注:我刚开始是不想通过form提交的,用js window.location.href 跳转到不同的action去处理,发现
    <base target="_self"> 就不起作用了,似乎 <base target="_self"> 只是针对form action="" 才起作用,这个地方应该可以用iframe 去实现。

  • 相关阅读:
    BZOJ3560: DZY Loves Math V(欧拉函数)
    BZOJ2693: jzptab(莫比乌斯反演)
    洛谷P1829 [国家集训队]Crash的数字表格 / JZPTAB(莫比乌斯反演)
    BZOJ3884: 上帝与集合的正确用法(欧拉函数 扩展欧拉定理)
    codeforces757E. Bash Plays with Functions(狄利克雷卷积 积性函数)
    等差数列与等比数列
    Codeforces#498F. Xor-Paths(折半搜索)
    在驱动和应用程序间共享内存
    Documentation/sched-bwc.txt 的中文翻译
    Windows NT 驱动程序开发人员提示 -- 应注意避免的事项
  • 原文地址:https://www.cnblogs.com/xiaolinshushu/p/2949650.html
Copyright © 2011-2022 走看看