This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Close main window from popup window

 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From a main page (called main.jsp) i open a popup window. From this popup window I want to close both the main page and the popup window just after submitting some data.

How can I close the main window from my popup window (without prompting the user)?

I tried the following code (used in my popup window), but it does only close the popup window:

function updateParticipant(){

document.form1.action="/servlet/AddParticipant";
document.form1.submit();

//Close the main window but it doesn�t work?
window.parent.close();

//Close popup window
window.close();
return false;
}
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64835
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeppe Fjord:
How can I close the main window from my popup window (without prompting the user)?


You can't, thank goodness.

Don't you think that would be a tad rude if it were allowed?
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:


You can't, thank goodness.

Don't you think that would be a tad rude if it were allowed?


Yes I agree. In some situations it would be very rude :-)

But what I wish to do, is to pass some data from the popup window to a servlet. The servlet does some data manipulation and save the data into a session, and then the servlet redirects back to the main.jsp page. The updated (manipulated) data is then going to be showed here.

If I only use the function window.opener.reload(true) in my popup window then I "sometimes" have to refresh the main.jsp page manually before the updated data is shown.

What can I do to ensure the main.jsp always shows the updated data being manipulated in the servlet?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
window.opener.location.href = window.opener.location.href;

and make sure to set the page to not to cache the page.

Eric
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I still have to refresh the main.jsp page manually before the updated data is showed.

I�ll try to explain the situation:
1) From main.jsp I open a popup window (popup.jsp) to edit some data (by a user).
2) From popup.jsp I want to pass the edited data (by a user) to a servlet when pushing the submit button. The popup.jsp has to close.
3) The servlet does some data manipulation and save the data in a session. Then it redirects back to main.jsp
4) Main.jsp then shows the updated data stored in the session.

Here is the javascript code I use in the popup.jsp, but it doesn�t work. I still have to update main.jsp manually sometimes. I think it depends on how fast the servlet does the data manipulation?!:

[ August 01, 2007: Message edited by: Jeppe Fjord ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Make sure you set the headers to not cache the page.
2) do not use the JavaScript to load the opener right away. Instead when you form is done processing, have it return the JavaScript that closes the window and refreshes the parent.

So: Submit the form, process data on server, page renders with JavaScript to reload and close.

Ideally I would avoid pop up windows and use Ajax, but that is a different story.

Eric
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ideally I would avoid pop up windows and use Ajax, but that is a different story.

Do all browsers support Ajax. Are there any drawbacks using Ajax?
[ August 01, 2007: Message edited by: Jeppe Fjord ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64835
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeppe Fjord:

Do all browsers support Ajax. Are there any drawbacks using Ajax?


All modern commonly-used browsers support Ajax.

The major drawback is that you need to get pretty cozy with JavaScript.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic