• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Close main window from popup window

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
}
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic