1、在一个页面中,打开模式窗口
- winoption ="dialogHeight:"+sheight+"px;dialogWidth:"+ swidth +"px;status:yes;scroll:yes;resizable:yes;center:yes;";
- window.showModalDialog(basepath+"/jsp/addVersion.jsp",window,winoption);
模式窗口在执行form的submit动作时,会打开一个新的页面,刚开始试了target的"_self",还是会打开新窗口。
接着试了下面的方法:
- <script type="text/javascript">
- window.name = 'addVerWin';
- </script>
然后在form的target加入:
- <form action="" id="xxForm" method="post" target="addVerWin">
该方法可以防止打开新页面,但是我后台servlet response的
- response.getWriter().print("<script type='text/javascript'>alert('版本标识[ID] "+vBean.getAPP_VERSION_ID()+" 已经存在!请重新输入!');window.history.back();</script>");
无法执行window.history.back() ,
想起来,模式窗口的location好像是不可以控制的。
实在没办法,又想了个办法,在模式窗口中,加入iframe,解决方法如下:
- <iframe src="" id="tempFrame" name="tempFrame" style="display: none;"></iframe>
- <!-- 添加新版本 -->
- <form action="manageServlet?task=addVersion" method="post" target="tempFrame" enctype="multipart/form-data">...</form>
后台通过
parent.window.parentWin.location=parent.window.parentWin.location; 来控制模式窗口父窗口的刷新。
通过加入iframe,然后把form的target指向该iframe,解决该问题。
转载于:https://blog.51cto.com/ashin1987/935573