wood burning stoves*
The moose likes HTML, CSS and JavaScript and the fly likes How to capture popup window close event. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to capture popup window close event." Watch "How to capture popup window close event." New topic
Author

How to capture popup window close event.

Puneet Chachra
Greenhorn

Joined: Nov 19, 2008
Posts: 8
Hi Experts,

I am launching one jsp page from another environment as popup window. I have to capture the popup window's close event when user clicks on close sign on the browser.
I have used "onbeforeunload" attribute of body tag. This works if my jsp is launched on independent browser not as popup window.
Please help me.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Puneet can you elaborate what you mean by pop-up window. I would say that they are the same thing. Are you using a popup javascript code like this



If yes, then this should not be a problem as both the popup and the original page would have the same source code. Please tell a little bit more about your problem...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Please take the time to choose the correct forum for your posts. This forum is for questions on JSP, not JavaScript.

For more information, please read this.

This post has been moved to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Puneet Chachra
Greenhorn

Joined: Nov 19, 2008
Posts: 8

Ankit, thanks for giving time to my problem. I tell you the exact scenerio. One applet is launched as a popup on click of a button from one environment, then a url is attached with this applet.

Means then my application is launched i.e. jsp page is launched in this applet, on that jsp close button is there. on click of close button, i perform some work. The same work i want to perform when user direct click on that applet close [*] button. I have used window's default functionality i.e. "onunload" or "onbeforeunload" functions, these functions work well if i launch my url in independent internet explorer, but in that applet popup, these are not working.
Puneet Chachra
Greenhorn

Joined: Nov 19, 2008
Posts: 8
Bear Bibeault wrote:Please take the time to choose the correct forum for your posts. This forum is for questions on JSP, not JavaScript.

For more information, please read this.

This post has been moved to a more appropriate forum.



Dear Bibeault,

You must be knowing that what functionality i need is only possible through java script. If i write html page in place of jsp, then my question would be treated perfect for this forrum.
Please dnt do that. You are most welcome if you can solve my problem. Otherwise let others solve it.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Puneet Chachra,

Bear moved you post so people that know how to solve your problem would see it. He is not required to solve it. Be happy he moved it to the correct location and did not leave it in a place where people do not code JavaScript hang out. Just because it is a JSP means nothing. The technology you need is JavaScript and it acts no different on a JSP, .NET, CF, ASP, PHP, CGI, etc.

Your tone also did not come through nicely in your post. Remember that the posters here at JavaRanch are volunteers. We are trying to help you succeed at your job and studies. We are working free of charge to help you solve something that you are most likely getting paid for or graded on.

Eric Pascarello
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
If you want to capture the close button of the pop up window, than you would have to put the onbeforeunload or onunload in the pop up window and not in the parent window.

You would probably be better using a modal window where a value is returned when the window is closed. No need to reinvent the wheel.

Eric
Puneet Chachra
Greenhorn

Joined: Nov 19, 2008
Posts: 8

Thanks Eric. Extremely sorry actually i have not understood properly what Bear has done.

Continuing with the thread, i have used onunload or onbeforeunload function in an html page which is launching in that applet popup window, but how they are working when i click on the button that launches that popup. It means that these functions are working but on parent window.
How can i achieve this on popup window? Is there any different syntax in body tag as i have used <body onbeforeunload="fnUnloadHandler1()" onunload="fnUnloadHandler2()">. Please clear me on this.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Did you declare the functions also in the pop up window or are they only declared in the parent.

If in the parent you can use window.opener.functionName()

Eric
Puneet Chachra
Greenhorn

Joined: Nov 19, 2008
Posts: 8

Yes Eric. I have declared the functions in a jsp which is launched in that popup window. My application has no concern with parent window. Through parent window, a new web application is called just through one link & jsp is displayed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to capture popup window close event.
 
Similar Threads
Popup - File Download
Closing the browser
Open a window on close of main window
How to handle window closing event.
pop up in jsp