I'm using Ctrl+Left / Ctrl+Right in a GreaseMonkey script as a hotkey to turn back / forward pages. It seems to works fine, but I want to disable this behavior if I'm in a text edit area. I'm trying to use document.activeElement to get the page active element and test if it's an editable area, but it always returns "undefined".
+2
A:
document.activeElement works for me in FF3 but the following also works
(function() {
var myActiveElement;
document.onkeypress = function(event) {
if ((myActiveElement || document.activeElement || {}).tagName != 'INPUT')
// do your magic
};
if (!document.activeElement) {
var elements = document.getElementsByTagName('input');
for(var i=0; i<elements.length; i++) {
elements[i].addEventListener('focus',function() {
myActiveElement = this;
},false);
elements[i].addEventListener('blur',function() {
myActiveElement = null;
},false);
}
}
})();
Jimmy
2008-09-03 23:18:44
A:
@Jimmy:
I'm using FF 2.0.0.16 until my extensions runs in FF3. It looks like activeElement doesn't work in FF2, but the focus/blur events did the trick, thanks
PabloG
2008-09-04 02:55:05
A:
element.activeElement is part of HTML5 spec but is not supported by most browsers. It was first introduced by IE.
thesmart
2009-01-03 21:59:38