views:

50

answers:

3

Hi,

I have a code like this: (this is a pop-up)

<body onblur="window.focus();">
<form id="ronny">
<select id="select1" name="select1">
<option> 1b </option>
<option> 1a </option>
</select>
<select id="select2" name="select2">
<option> 2b </option>
<option> 2a </option>
</select>

Now, my problems are:

  1. In FF - when i move to the main window, the onblur event is not fire.

  2. In IE - when i click on the select in order to select an option, the event is fired.

I want the event will fire only when the user select an other window than the pop-up. Is it possible?

I tried also onfocusout but this is not working in both browsers.

Thank you!

+1  A: 

Give this up. You're trying to make a window grab the focus whenever it loses it, thus keeping it forever focussed? That's possibly the most annoying behaviour in the world. Browsers won't let you do this, happily.

Quirksmode has some decent information on focus and blur events: http://www.quirksmode.org/dom/events/blurfocus.html and http://www.quirksmode.org/blog/archives/2008/04/delegating_the.html

Tim Down
A: 

Please, please, please, for the love of all that is web design, do not implement this (if it's possible to do). You are taking over a users control, and NOTHING, should EVER do this whilst they are browsing. It's what gives web developers a bad name!

Alex
+1  A: 

You can't.

In webdesign philosophy, you have control over everything in the window, but not of the window itself (yes, there are javascript parts that violate this, such as resizing the window, but they're evil and the point is still valid).

Trying to do this is futile and wrong. Every decent browser will not allow it, and if you find one that does, it's probably a bug.

Joeri Hendrickx