What you could do is when you open the pop-up window set a global variable on the parent window so the page knows the pop-up window is open, then in the body tag of the parent window set the onFocus to goto a function which checks if the global variable is set and if so closes the pop-up window.
This would, however, cause problems if there were any form field elements on the popup. Focusing on a field element will cause the onblur method of the body to be called.
*cLFlaVA
----------------------------
"Holy crip he's a crapple!
Good point - and unfortunately, moving the onblur handler from the body to the window makes it even worse, as the behaviour differs from browser to browser then.
One way around this would be to write an onblur handler for the body, which runs a setTimeout to close the window after, say, 250msecs.
All elements on the page could have their onfocus events pointing to a generic handler which simply cancelled the setTimeout. The onfocus handlers could be set for all elements quite easily with javascript.
Hmmm - I've been doing some playing with the idea, and it seems that, at least with IE, it is not be possible to do it with 100% "common sense factor" built in...
What I mean by this is that it would work most of the time, but there are a few things that don't seem possible to detect - primarily:
My idea above works fine when clicking around on elements within the window (that can have a focus handler attached), but when clicking between the window and the address bar (which we cannot harness), the window would still close.
Of course, it being a popup means that you may choose to open it without an address bar... If it does not have one, the idea is quite workable - although it is still possible that things like alert boxes, popup menus, other browser modifications, etc, which cannot have a focus will still cause the window to close.
After looking into it, I'd say that it probably isn't worth (a) the hassle, or (b) the chances of a false positive.
Hope this helps,
Dan
what we would class as being blurred is not really always detectable
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.