<p>I'm using <kbd>Ctrl</kbd>+<kbd>Left</kbd> / <kbd>Ctrl</kbd>+<kbd>Right</kbd> 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".</p>

[{'answer_id': 42807, 'author': 'Jimmy', 'author_id': 4435, 'author_profile': 'https://Stackoverflow.com/users/4435', 'pm_score': 3, 'selected': True, 'text': "<p>document.activeElement works for me in FF3 but the following also works</p>\n\n<pre><code>(function() {\n\nvar myActiveElement;\ndocument.onkeypress = function(event) {\n    if ((myActiveElement || document.activeElement || {}).tagName != 'INPUT')\n        // do your magic\n};\nif (!document.activeElement) {\n    var elements = document.getElementsByTagName('input');\n    for(var i=0; i&lt;elements.length; i++) {\n        elements[i].addEventListener('focus',function() {\n            myActiveElement = this;\n        },false);\n        elements[i].addEventListener('blur',function() {\n            myActiveElement = null;\n        },false);\n    }\n}\n\n})();\n</code></pre>\n"}, {'answer_id': 409951, 'author': 'thesmart', 'author_id': 20176, 'author_profile': 'https://Stackoverflow.com/users/20176', 'pm_score': 0, 'selected': False, 'text': '<p>element.activeElement is part of HTML5 spec but is not supported by most browsers. It was first introduced by IE.</p>\n'}]
['https://Stackoverflow.com/questions/42774', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/394/']