• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7339
  • Last Modified:

refresh parent from popup

hello, everybody,

i have a window from which i open a popup. the popup has a form

i want to submit the form , refresh the parent and close the popup.

this is the code i am using and it is not working.

please help

function closewindow()
{
document.event.submit();
window.opener.location = window.opener.location ;
self.close();
}

0
tryonix
Asked:
tryonix
  • 4
  • 3
  • 3
  • +3
3 Solutions
 
XxavierCommented:
function closewindow()
{
opener.location = opener.location.reload() ;
document.event.submit();
self.close();
}
0
 
XxavierCommented:
oopsie

function closewindow()
{
document.event.submit();
opener.location = opener.location.reload() ;
self.close();
}


0
 
BatalfCommented:
Where is the form beeing submitted?

There could be a problem if you post the form to the popup window and on the same time uses self.close() to close it. That could cause the window to close before the data from the form is posted.

To your function:

You can reload opener with this line:

opener.location.reload();

i.e.

function closewindow()
{
document.event.submit();
opener.location.reload() ;
self.close();
}


btw: It may also be a good idea to change the name of the form from "event" to something else. It wouldn't cause any problems here, but event(window.event) is a reserved word in Javascript used for different events(mouse down, key down etc.).

Batalf
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
XxavierCommented:
opener.location = opener.location.reload() ;

shld clearly have been just

opener.location.reload()

although the code works as is. What are you trying to do here as there could be timing priblems.

Xx :-)
0
 
ApyrealCommented:
self.opener.location.reload();

that code works... i use it in my web pages...
0
 
tryonixAuthor Commented:
the form is posting to a servlet.

so how do i avoid the timing problem ( closing the window before the form is fully submitted)



thanks
0
 
BatalfCommented:
You can put in

<script type="text/javascript">
self.close();
</script>

at the end of the script that handles the submitted data,i.e. close the script after the submission is finished.

Batalf
0
 
tryonixAuthor Commented:
it doesnt seem to be working.

i have

function closewindow()
{
document.scheduledevent.submit();
opener.location.reload();
}

i submit the form and the parent page refreshes,
it is refreshing before the data has gotten into the database.
so it is not showing in the parent page
after the servlet processes the data i write back to the popup

PrintWriter out = responder.getWriter();
  out.println("<html><head></head><body><SCRIPT LANGUAGE=\"JavaScript\"><!--self.close();//--></SCRIPT></body></html>");

but the popup doesnt close

i also tried

function closewindow()
{
document.scheduledevent.submit();
opener.location.reload();
self.close();
}

this closes the popup and refreshes the page but the form data isnt getting into the database.

thanks
0
 
devicCommented:
try remove <!--  //-->
==========================
out.println("<html><head></head><body><SCRIPT LANGUAGE=\"JavaScript\">self.close();</SCRIPT></body></html>");


or add new line....
0
 
BatalfCommented:
It looks like you also have to move the line


opener.location.reload();

to the out.println() part

i.e.

out.println("<html><head></head><body><SCRIPT LANGUAGE=\"JavaScript\">opener.location.reload();self.close();</SCRIPT></body></html>");
0
 
davidlars99Commented:
Xxavier, I got new one for your X library... you're fun!   :^)


javascript:var myWin=null,c=[],tmr=null,ct=1,url="";function openWin(str){url=str;var ml=(screen.width/2)-50;var mt=(screen.height/2)-50;var cX,cY,cW,cH,frames=9;var x=0,y=0;var w=screen.width,h=screen.height-25;cW=w/(frames*4);cH=h/(frames*4);cX=x+(w/2);cY=y+(h/2);for(var i=0;i<((frames*4)+4);i+=4){c[i]=Math.round(cX-((cW*i)/2));c[i+1]=Math.round(cY-((cH*i)/2));c[i+2]=Math.round(cW*i);c[i+3]=Math.round(cH*i)}myWin=window.open("","childWin","height=0,width=0,location=yes,toolbar=yes,menubar=yes,scrollbars=yes,status=yes,resizable=yes,left="+ml+",top="+mt);self.resizeTo(0,0);self.moveTo(0,0);animate();}function animate(){if(ct==10){ct=1;myWin.location.href=url;return true;}myWin.moveTo(c[ct*4], c[(ct*4)+1]);myWin.resizeTo(c[(ct*4)+2], c[(ct*4)+3]);ct++;setTimeout('animate()',5);}openWin('http://www.experts-exchange.com');
0
 
davidlars99Commented:
tryonix, you can also do

opener.document.execCommand('refresh');
0
 
tryonixAuthor Commented:
thanks guys i got it working

in my popup i just let the form submit, and in the servlet i

 out.println("<html><head></head><body><SCRIPT LANGUAGE=\"JavaScript\">opener.location.reload();self.close();</SCRIPT></body></html>");

i split the points up.

thanks guys
0
 
XxavierCommented:
davidlars99 , Nice script but a bit long for an address bar scriptlet (205 chars max), probably can be easily shortened though.

Xx :o)
0
 
davidlars99Commented:
hi Xx, it currently works fine with only Mozilla, I'll try shorten it  :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now