Ben's House of Pancakes
onblur events in Firefox
Firefox seems to have a problem with onblur events. The onblur handler is not called when the componant is clicked out of, only when tabbed out. Here is a simple solution to the problem.
var action = function(){
//whatever action you want to happen onblur
}
if (document.addEventListener) {
document.addEventListener('click', action, false);
} else if (document.attachEvent) {
document.attachEvent('onclick', action, false);
}
The down side:
It is called on _any_ blur, so literally anytime a click happens on the document, but it works for simple things like hiding auto-complete drop downs.
Posted at 01:54PM Jun 09, 2007 by Benjamin Say in General | Comments[5]
That's rather interesting. However, I couldn't duplicate your bug in Firefox 2.0.0.4.
Did you have any other events assigned to the field (onclick, onchange, etc)? Where you using any frameworks that might modify the behavior of the element such as prototype or scriptaculous?
Also, you might be interested in Jason's post about syntax highlighting in your blog.
Posted by Jesse Bethke on June 09, 2007 at 07:41 PM CDT #
A Google search showed that many others have had a similar problem. Yes, the field has other things like onclick associated with it. Both prototype and scriptaculous are being used.
At any rate, it fixed the problem.
Posted by Benjamin Say on June 10, 2007 at 02:44 PM CDT #
do you have a url of an example page where this issue is happening? Id be curious to see this myself (not that i doubt you, Ive been doing a lot of JS lately in a large outside project, and may be running into the same or similiar issue with the scriptaculous lib.)
Posted by Jason Johnson on June 11, 2007 at 02:20 PM CDT #
I do not currently have a page online where this is happening. I could see about creating one, but it might be a bit before it goes online.
There is this example page which I do believe is having the same issue, though I haven't looked into it too thoroughly: http://www.codeproject.com/jscript/jsactb.asp
Posted by Benjamin Say on June 11, 2007 at 04:13 PM CDT #
ehi hello
chat
Posted by cico on September 11, 2008 at 10:19 AM CDT #