File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Close main window from popup window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Close main window from popup window" Watch "Close main window from popup window" New topic
Author

Close main window from popup window

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
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

Joined: Jan 10, 2002
Posts: 60775
    
  65

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jan 07, 2004
Posts: 270
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jan 07, 2004
Posts: 270
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

Joined: Jan 10, 2002
Posts: 60775
    
  65

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Close main window from popup window
 
Similar Threads
How to capture popup window close event.
Check if popup window is already open from parent window?
Submit form and close window
Closing popup windows that have timed out
Print the main page after confirmation page is closed