Link to home
Start Free TrialLog in
Avatar of tryonix
tryonix

asked on

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();
}

Avatar of Xxavier
Xxavier
Flag of Canada image

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

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


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
SOLUTION
Avatar of Xxavier
Xxavier
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
self.opener.location.reload();

that code works... i use it in my web pages...
Avatar of tryonix
tryonix

ASKER

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
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
Avatar of tryonix

ASKER

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
SOLUTION
Avatar of devic
devic
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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');
tryonix, you can also do

opener.document.execCommand('refresh');
Avatar of tryonix

ASKER

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
davidlars99 , Nice script but a bit long for an address bar scriptlet (205 chars max), probably can be easily shortened though.

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