Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can't get my child window to close and reload the parent.

 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want the following scenario:

1 User clicks on a link
2 Popup window opens.
3 XXXXX - See below.
4 Popup disappears
5 original window reloads.

So I've got the link to pop open the window (1, 2). I've got the code that will work to close the child window and reload the parent (4, 5).

What is not working right now, is 3.
I want a form submission to take place, and after it's done processing, proceed with steps 4,5. I've googled around a bit, and several sites instruct me to use javascript to submit the form, and then proceed with steps 4,5, all from within the popup. The problem with this is, the form might not be processed (server-side) before my first page reloads. I want to be absolutely certain the form has completed processing. So what I've done is made a servlet that does the form processing (3), then outputs the HTML/javascript required to produce steps 4, 5. In this way, I guarantee the main page is not reloaded until it's ready to.

Here is the code:


So , if you create a popup window with nothing but the above... then it works 'perfectly'... step 1,2,4,5 happen all as expected. But when the HTML/javascript above, is produced as the output of a form submission from within the popup, I get an error. On Mozilla, it just sits there with a blank screen. On IE, the error is:
Line: 5
Char: 4
Error: Access is denied

I suppose what's happening is, the result of the form submission is "some other page" and the 'opener' object is not maintained. I thought it would be, because I thought it was a 'window' attribute.

any ideas?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, off the top of my head I would have expected opener to remain valid since you are only swapping out the document. Oh well...
How about if you submit your form into an invisible iframe? That way the original page, with opener intact would remain across the submission. The response to the submission could alert its parent that it's done, which would trigger the close and reload of the opener. A bit messy, but may work for you.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear,

That idea scared me a bit. So I looked harder.

This was my problem:
http://www.dannyg.com/ref/jsminifaq.html#q15

I was popping open the child window from the parent's domain, but the response from the servlet came from a subdomain. Since the subdomain was an alias anyways, I set them both the same, and now it works.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I assumed that the pages came from the same webapp/domain. I guess that should've been the first thing to check!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic