views:

35

answers:

2

I want to

A) open a pop up window via javascript - easy enough

B) close this window via Javascript - easy enough

C) ensure that the window that spawned the popup in A is focused on again when close in B. Seem to remember can do this but can't remember how.

+3  A: 

script for closing child window and put focus back on parent window

window.opener.focus(); 
window.close();
Pranay Rana
A: 

Probably the user can close the popup in many ways as with a link, button or close button so a good way is to use the event onunload

so put this in the popup window

window.onunload = function(){
   window.opener.focus(); 
}
Luka
I find this has side effects (will take you to the opener) when you press F5 on the popup window in internet explorer 8
AJM
@AJM yes for sure, the `onunload` event is triggered if the popup window is reloaded. My answer was to help you as your question to give the focus back to the opener, btw what will happen if the user close the popup with the button on top right ? You can't control that so that's why i suggest to use the `onunload` event. You can add a script in the popup `window.onload=function({self.focus();}` to get the focus back in the popup in case of reload.
Luka
Yes, thanks for the help. I think I will just stick with the if they don't click on my link then then its tough luck. Interesting idea though.
AJM