By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,795 Members | 1,235 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,795 IT Pros & Developers. It's quick & easy.

Closing pop up window on exit of main window in java script

P: 3
Hi,

I open a window using window.open('win1') from a parent window, now this pop up window will have to be open until user uses the application.
On click of logoff or 'X' button on browser the pop up window needs to be closed on it self.

How can I do this?
I tried onunload(), window.parent but nothing working....basically
var myRef=winow.open(win1) will give a object refrence but this object will be active only for that page....how can i access this across the application.

Please let me know if any suggestions.

Regards,
Pramod
Oct 20 '08 #1
Share this Question
Share on Google+
6 Replies


Nepomuk
Expert 2.5K+
P: 3,112
As this is a JavaScript Question instead of a Java Question, I'll move it to the JavaScript / Ajax Forum.

Check the Wikipedia Java article, if you don't know the difference between Java and JavaScript.

Greetings,
Nepomuk (Moderator)
Oct 21 '08 #2

acoder
Expert Mod 15k+
P: 16,027
The pop-up window would have access to its parent through window.opener. You could periodically check that the reference is not null and then close automatically if it is.
Oct 21 '08 #3

P: 3
The pop-up window would have access to its parent through window.opener. You could periodically check that the reference is not null and then close automatically if it is.
Could you please post some JS snippet for the same.
Oct 21 '08 #4

P: 55
Expand|Select|Wrap|Line Numbers
  1. setInterval(chkParWin,2000)
  2.  
  3. function chkParWin(){
  4. if(!window.opener || (window.opener=='null')){
  5. window.close()
  6. }
  7. }
that should check every couple seconds to see if the window you opened your popup from is still there
Oct 21 '08 #5

P: 3
Expand|Select|Wrap|Line Numbers
  1. setInterval(chkParWin,2000)
  2.  
  3. function chkParWin(){
  4. if(!window.opener || (window.opener=='null')){
  5. window.close()
  6. }
  7. }
that should check every couple seconds to see if the window you opened your popup from is still there

------------
Thanks for the reply, but this will prompt user a message,
I am still having the same issue. Let me detail more:-

in main JSP I call a pop up saying
myWin1= window.open("url", win1); (this would open (popup)another JSP)

now this JS function is present inside a JSP. The logoff button of application is in different JSP, onClick of this button I call a function closeWindows().

function closeWindows(){
//chk for wind closed or open then
myWin1.close();
}

but the variable myWin1 will have [object] only if I exit from the same page, when I navigate to different page this varibal will be null and cannot be closed.
Is there a way or possible to keep track of the JS object in different JSPs.
Oct 21 '08 #6

acoder
Expert Mod 15k+
P: 16,027
No, there isn't which is why the suggestion is to close from the child window instead.
Oct 22 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.