views:

63

answers:

2

I did a quick search, but couldn't find a specific solution to this (I'm sure it HAS been answered) but, I need to figure this out...

Anyone know why this won't work in IE?

$(document).ready(function() {
    $(document).blur(function() {
        window.close();
    });
});

And what to do instead? Thanks.

A: 

I'm fairly certain that you can't detect a click outside the window itself, which seems to be what you're trying to do.

I would recommend a dialog box instead of a new window if you want it to close. They have nifty features like loading in whole other pages, and even iframes.

contagious
I'm down with this solution... I've been using Facebox. The only problem I have is I need a javascript function to fire the dialogue box and facebox looks for an href... I'm a little tired of looking up dialogue boxes at the moment... gahhhhh
Jascha
Well, I ended up going with your idea... a dialogue box. I can't say you really answered the question, but it worked so I'll give you the check mark.
Jascha
well, you can't really capture the `blur` event of the `body` because it's not an input, which is mostly what `blur` is for. blur = when it loses focus. and since 'body' or 'document' can't have focus (a cursor in it) it can't logically have a blur. it seemed like you were trying to capture when you click outside the window, which is more like a dialog box behavior.
contagious
+1  A: 

try binding the blur to body instead of document

carillonator
this worked. I gave the body an ID tag and bound it. I had to keep the $(document) too for all the other browsers that actually work.
Jascha
I take it back. It didn't work. Anytime you click anything, the window closes.
Jascha
try adding `$('body').click(function() { return false; });`
carillonator
I ended up using contagious's solution, but I gave you an up vote for being helpful and very close to the answer.
Jascha