Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
focusin focusout support for firefox
/* Copyright (c) 2016 Tobias Buschor | MIT License */
/* focusin/out event polyfill (firefox) */
var w = window,
d = w.document;
if (w.onfocusin === undefined) {
d.addEventListener('focus' ,addPolyfill ,true);
d.addEventListener('blur' ,addPolyfill ,true);
d.addEventListener('focusin' ,removePolyfill ,true);
d.addEventListener('focusout' ,removePolyfill ,true);
function addPolyfill(e){
var type = e.type === 'focus' ? 'focusin' : 'focusout';
var event = new CustomEvent(type, {bubbles:true, cancelable:false});
event.c1Generated = true;;
function removePolyfill(e){
if (!e.c1Generated) { // focus after focusin, so chrome will the first time trigger tow times focusin
d.removeEventListener('focus' ,addPolyfill ,true);
d.removeEventListener('blur' ,addPolyfill ,true);
d.removeEventListener('focusin' ,removePolyfill ,true);
d.removeEventListener('focusout' ,removePolyfill ,true);
d.removeEventListener('focusin' ,removePolyfill ,true);
d.removeEventListener('focusout' ,removePolyfill ,true);
Copy link

arnaudleyder commented Aug 4, 2015

Thanks. That does the trick. FF still does not support these events in August 2015. They did drop the ball at some point in time.

Copy link

Gonzalo2683 commented Mar 1, 2016

How to use?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment