window.open()或window.showModalDialog开启新窗口后,如果有form submit 或window.loaction动作,系统会打开一个新的页面。如果想操作还在原来打开的窗口则需要加点修改:
添加一个popupWindow.jsp
<%String sSourceURL = (String)request.getParameter("src");%>
<html>
<body>
<iframe name="childFrame" id="childFrame" height="100%" width="100%" src="<%=sSourceURL%>"></iframe>
</body>
</html>
系统不直接打开url,而是先转给popupWindow.把src放入一个iframe中,来保证后面的操作不会新开一个窗口。
如:
function openPhotoWin(staffCode)
{
src = 'popupWindow.jsp?src='+escape("maintEmployeePhoto.do?method=init&staffCode="+staffCode);
openChildWindow(src, '', 'dialogWidth: 778px; dialogHeight:560px; center: Yes; help: no; status:no;', 'Y');
}
//open child window
function openChildWindow(src, inputObj, windowStyle) {
var pageStatus=true;
aReturn = window.showModalDialog(src, inputObj, windowStyle );
return aReturn;
}
上面例子中src为链接,其中还带两个参数method,staffCode
maintEmployeePhoto.do?method=init&staffCode="+staffCode
如果src = 'popupWindow.jsp?src='+escape("maintEmployeePhoto.do?method=init&staffCode="+staffCode);
改为src = 'popupWindow.jsp?src='+"maintEmployeePhoto.do?method=init&staffCode="+staffCode;
在popupWindow.jsp中,系统 String sSourceURL = (String)request.getParameter("src");
sSourceURL =maintEmployeePhoto.do?method=init;
而我原本想要 sSourceURL =maintEmployeePhoto.do?method=init&staffCode=staffCode;
可以比较出来前一中方法把staffCode变量已经丢掉,而这不是我想要的。为什么这样呢?因为前中方法,系统默认&staffCode为 popupWindow.jsp所有,而src拿不到。
通过 escape("maintEmployeePhoto.do?method=init&staffCode="+staffCode)就可以把整个值传给src 了。