我的预期目的是由主窗口弹出一个子窗口,这个子窗口上有一个表单,我想让这个表单提交后,自动关闭这个子窗口,相关代码如下:function addSeed(parmater){
if(parmater == '2'){
if (confirm("登记确认后将不能进行任何操作,是否继续?")){
document.forms[0].action = "<%=request.getContextPath()%>/product/tjgl.do?method=tj_addimport&savep=" + parmater;
document.forms[0].submit();
return this.window.close();
}else{
url = "";
}
}else{
document.forms[0].action = "<%=request.getContextPath()%>/product/tjgl.do?method=tj_addimport&savep=" + parmater;
document.forms[0].submit();
return this.window.close();
}
}表单按钮的onclick事件绑定了这个js函数。
现在的问题是表单似乎没有执行提交就已经关闭了,也就是说,不管到哪个分支,这个函数只执行了return this.window.close(),没有执行其他的代码,请问该如何是好?小弟谢谢大家了!
if(parmater == '2'){
if (confirm("登记确认后将不能进行任何操作,是否继续?")){
document.forms[0].action = "<%=request.getContextPath()%>/product/tjgl.do?method=tj_addimport&savep=" + parmater;
document.forms[0].submit();
return this.window.close();
}else{
url = "";
}
}else{
document.forms[0].action = "<%=request.getContextPath()%>/product/tjgl.do?method=tj_addimport&savep=" + parmater;
document.forms[0].submit();
return this.window.close();
}
}表单按钮的onclick事件绑定了这个js函数。
现在的问题是表单似乎没有执行提交就已经关闭了,也就是说,不管到哪个分支,这个函数只执行了return this.window.close(),没有执行其他的代码,请问该如何是好?小弟谢谢大家了!
解决方案 »
- Eclipse+Spring出现javax.servlet.ServletException: Servlet.init()..错误
- 数据库关闭和连接资源问题
- java 程序员每年什么时间好找工作啊
- ★★★★请大家指点下关于hibernate的这段代码★★★★
- style report 报表设计器函数有可以提供的吗?
- 在线等,关于部署EJB后,在通用测试服务器下遇到的问题
- 编译java程序时,出现的问题。
- jbuilder 的注册问题
- 请教request.getSession().getServletContext().getRealPath("/");这句话获取的是服务器路径吗?
- log4j继承问题
- 用java来实现一个简答的银行转账问题?
- 请教:Hibernate分页的好办法
你可以去掉return this.window.close();这一句,后台处理提交的表单字段之后PrintWriter writer = response.getWriter();
writer.write("<html><body onload=\"window.close()\"></body></html>");
return null;或则跳转到一个jsp,jsp的内容类似于上面那样。
如果不接收从后台传回的对提交的回应,并根据回应来决定后续的显示内容,你看到的本来就该是现在这样。如果要由后台回应来决定前台的后续显示,前台Js的逻辑就不该是这样。应该由后台来决定转向至哪个页面,或者以Ajax来接受后台回应并在回调函数中关闭窗口。
别这样写
直接这样写 this.window.close(),
try{
xmlHttp = new XMLHttpRequest();
}catch(tryMicrosoft){
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(otherMicorsoft){
try{
xmlHttp = new ActiveXObject("Micorsoft.XMLHTTP");
}catch(otherChrome){
xmlHttp = false;
}
}
} var hasClosed;
function closeWin(){
hasClosed = true;
window.opener.location="javascript:reloadPage();";
window.opener = null;
window.close();
} window.onbeforeunload = function(){
if(!hasClosed){//如果已经执行了closeWin方法,则不执行本方法
window.opener.location="javascript:reloadPage();";
}
} function reloadPage(){
history.go(0);
document.execCommand("refresh")
document.location = document.location;
document.location.reload();
}
function addSeed(parmater){
if(parmater == '2'){
if (confirm("登记确认后将不能进行任何操作,是否继续?")){
document.forms[0].action = "<%=request.getContextPath()%>/product/tjgl.do?method=tj_addimport&savep=" + parmater;
closeWin();
}else{
url = "";
}
}else{
document.forms[0].action = "<%=request.getContextPath()%>/product/tjgl.do?method=tj_addimport&savep=" + parmater;
closeWin();
}
}
现在的问题是B窗口确实能关闭,并且表单action也的确执行了,但主窗口A并没有自动刷新,需要手动刷新才行。而且在firebug上调试出现错误,说是reloadPage is not defined,我猜测是因为reloadPage()这个方法的作用域只限于子窗口B,但A似乎调用了这个方法,我不知道在哪里调用了这个方法才导致reloadPage is not defined这个错误,恳请您指点迷津,时间紧急,请多多关照啊,谢谢您。
之所以报出reloadPage is not defined错误,就是因为window.opener.location="javascript:reloadPage();";,相当于A窗口执行window.location="javascript:reloadPage();";,而你A窗口没有reloadPage方法。