一、方法一:使用window.open()方法。

在父窗口中的html代码:

<a class="btn btn-primary "  id="addnews"> 添加新闻</a>

在父窗口中的js代码,通过window.open()打开子窗口:

$("#addnews").click(function(){
    var url='manage/newsAdd.jsp?userId=<%=user.getNumber()%>'; //转向网页的地址;
    var name=''; //网页名称,可为空;
    var iWidth=700; //弹出窗口的宽度;
    var iHeight=400; //弹出窗口的高度;
    //window.screen.height获得屏幕的高,window.screen.width获得屏幕的宽
    var iTop = (window.screen.height-30-iHeight)/2; //获得窗口的垂直位置;
    var iLeft = (window.screen.width-10-iWidth)/2; //获得窗口的水平位置;
    window.open(url,name,'height='+iHeight+',innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');   
  });

子窗口中的html代码:

<%
    String result = (String) request.getParameter("res");
  %>
  <div class="container">
      <form method="post" action="NewsAdd?userId=<%=userId%>" id="newsform">
        <div class="panel panel-primary" >
            <textarea id="newsContent" name="newsContent" required="required" oninvalid="setCustomValidity('请输入新闻内容!')" οninput="setCustomValidity('')"
                 autofocus="autofocus" placeholder="请输入滚动新闻内容" rows="10" cols="60" style="border:0;"></textarea>
              </div>             
        </div> 
        <div style="margin:20px auto;">
          <input class="btn btn-primary" type="submit" value="提 交" id="submitbtn" /> <!--提交后返回该页面,返回值为res-->
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <button class="btn btn-default" οnclick="window.close()" id="cancel">取 消</button>          
        </div>
      </form>
    </div>
  </div>
  子窗口中的js代码:
  <script>    
    $(document).ready(function(){
      var result = <%=result%>;
      if(result==1){ //上传成功,登录成功等等        
        window.opener.location.reload();
        window.opener=null;                 //刷新父窗口,关闭子窗口
        window.close();
      }   
    });  
  </script>

这种方法没有采用遮蔽效果。

二、方法二:使用layer (http://sentsin.com/jquery/layer/ )的iframe层

首先在父窗口和子窗口页面添加<script src="Resources/layer/layer.min.js"></script>

在父窗口中的html代码:

<a class="btn btn-primary "  id="addnews"> 添加新闻</a>

在父窗口中的js代码,通过iframe()打开子窗口:

$('#addnews').on('click', function(){
    $.layer({
      type: 2, //iframe
      shade: [0.5,'#000'],
      fix: false,
      title: '添加一条记录',
      maxmin: false,
      border: [0],
      closeBtn: [0, true],
      fadeIn: 300,
      iframe: {src:'manage/newsAdd.jsp?userId=<%=user.getNumber()%>',scrolling: 'no'},
      area: ['580px' , '430px'],
      close: function(index){  //点击layer右上角关闭按钮触发的事件
        location.assign('NewsModify?userId=<%=user.getNumber()%>'); 
      }
    });
});

子窗口中的html代码:

<%
    String result = (String) request.getParameter("res");
  %>
  <div class="container">
      <form method="post" action="NewsAdd?userId=<%=userId%>" id="newsform">
        <div class="panel panel-primary" >
            <textarea id="newsContent" name="newsContent" required="required" oninvalid="setCustomValidity('请输入新闻内容!')" οninput="setCustomValidity('')"
                 autofocus="autofocus" placeholder="请输入滚动新闻内容" rows="10" cols="60" style="border:0;"></textarea>
              </div>             
        </div> 
        <div style="margin:20px auto;">
          <input class="btn btn-primary" type="submit" value="提 交" id="submitbtn" /> <!--提交后返回该页面,返回值为res-->
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <button class="btn btn-default" οnclick="window.close()" id="cancel">取 消</button>          
        </div>
      </form>
    </div>
  </div>
  子窗口中的js代码:
  $(document).ready(function(){
      var result = <%=msg%>;
      var index = parent.layer.getFrameIndex(window.name);
      if(result==1){ //上传成功              
        parent.location.reload(); //刷新父窗口
        parent.layer.close(index);
      }
      
      $("#cancel").click(function(){
        parent.layer.close(index);      
      });
    });

关闭子窗口父窗口刷新相关推荐

  1. java 父窗口关闭_javascrpt控制父窗口关闭,子窗口也关闭(转)

    var__winRoot__=top||parent||window;//祖先窗口对象var__winParent__=__winRoot__;//父窗口对象(默认为祖先窗口)var__winTree ...

  2. Win32-子窗口-父窗口-窗口所有者

    文章目录 1.窗口关系 2.窗口类型的说明和限制 3.几个相关函数的说明 4.作者答疑   在windows系统中,每个窗口对象都对应有一个数据结构,形成一个list链表.系统的窗口管理器通过这个li ...

  3. 关闭子窗口 父窗口自动刷新

    function clsoseForm() { window.opener.location.href=window.opener.location.href; window.opener.locat ...

  4. 子窗口关闭,父窗口有选择刷新

    在父窗口中打开一个模式窗口,当模式窗口关闭的时候父窗口不刷新. 父窗口js代码 function addDiaocha()  {   var url = '${ctx}/admin/diaocha/e ...

  5. javascript用window open的子窗口关闭自己并且刷新父窗口

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 在字窗口 ...

  6. 总结JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作

    前些日子,一直奔波于这三种操作,想想以后会常用,干脆整理下来,供自己以后查看.也给大家分享一下! 以下面写出自己认为有用的操作和代码. 第一次在园里面写,肯定有很多不足够之处,希望大家多多指点. 一. ...

  7. window.open window.showModelDialog 打开一个新窗口/子窗口中调用父窗口的方法

    window.open 只打开一个窗口是将 oNewWindow   =   window   .   open   (   sURL   ,   sName   ,   sFeatures   , ...

  8. js 弹出子页面与关闭子页面刷新父页面的问题

    在使用js弹出子页面并在关闭子页面的时候刷新父页面的时候遇到不能刷新的问题,为这个事郁闷了好久,在网上找相关的资料基本上都是使用window.opener.location.href=window.o ...

  9. mfc获取子窗口句柄_前端设计-JavaScript中父窗口与子窗口间的通信

    父窗体与子窗体之间的通信 在之前文章讲解windows程序设计过程中,我们曾描述了windows程序窗口之间通信与控制实现方法与过程,如窗体之间参数传递等.本文主要从Web程序开发前端JavaScri ...

最新文章

  1. java 字节数组 操作_Java-固定字节数组对象
  2. Codeforces Round #698 (Div. 2)
  3. python画图颜色表示大小变化_Python matplotlib减少色条标签的大小
  4. [转载] 中华典故故事(孙刚)——31 千里送鹅毛_礼轻情义重
  5. qscoj:喵哈哈村的卢西奥
  6. 设计模式12——代理模式
  7. 微服务架构 | 配置中心 - [Config]
  8. 数字电路基础(四) 数据分配器、数据选择器和数值比较器
  9. 应急指挥中心整体建设方案(ppt)
  10. 服务器安装找不到lsi驱动,IBM 服务器 SAS Raid LSI Windows2008 硬盘 驱动
  11. 零基础自学计算机方法大全
  12. 基于openstack构建私有云实践
  13. 卡尔曼滤波室内温度估计
  14. ISTQB TM考点总结之第三章
  15. 使用 Apple Watch S6 测量血氧教程
  16. arm二进制文件转换成c语言,转换非常简单的ARM指令将二进制/十六进制(Converting very simple ARM i...
  17. 简单的文本挖掘-用于QQ聊天记录(R)
  18. 【经验分享】Web前端开发测试常见问题总结
  19. java web 学习
  20. 基于ATmega16的自适应电压表

热门文章

  1. php exec pdfbox 方块,Windows explorer hangs up FTP connection after PASV command
  2. 固态硬盘量产复活记(慧荣SM2256K+H27QFG8PEM5R)
  3. 02:产品常用工具及网站
  4. pio读取 Excel中 电话号码和身份证的问题
  5. dns服务器未响应重启就好,网络诊断提示DNS服务器未响应解决方法 - 全文
  6. AppInventor 模拟器与AI伴侣 问题
  7. 【Unity开发】随手记:点击屏幕选中物体
  8. 使用Visio 2013 画跨职能流程图
  9. 软件测试/测试开发丨学习Docker就应该掌握的dockerfile语法与指令
  10. 2021-04-28 Mac上插入公式的三种方法