An Attempt to Find Focus

As you may have read from an earlier post I have been searching for a nice solution to figuring out which element currently has focus. Reason being is that it would be nice to detect if any element within Impromptu has focus, if not focus Impromptu. This way it keeps users from accessing the underlying page. The attempt I made was pretty simple: Apply focus event to ad a class name to the element, and to remove it on blur. Then I just need to search for that class name within the group of elements. My solution was a jquery plugin which looks like:

(function($){ $.fn.focusfinder = function() { this.each(function(i){ $(this).find('*').focus(function(){ $(this).removeClass('focusfinder').addClass('focusfinder'); }).blur(function(){ $(this).removeClass('focusfinder'); }); }); return this; }; })(jQuery);

Ok, maybe that isn't the most efficient solution, but its completely experimental. Anyway, to activate this puppy you would simply call this line to assign the events:


What I found was that different browsers fire focus and blur events differently, thus making my solution somewhat inaccurate. Firefox worked as expected, the others were a disappointment. Any ideas?