Is there a way in Javascript to determine if no elements are in focus? -
i'm building hotkeys page of html:
$(document).bind('keypress', function (e) { var event = (e.keycode ? e.keycode : e.which); if (event == letter_p) { // go page } } but problem if entering text on page (in textbox element, etc) , hit letter 'p', off page. want redirection happen if not in elements.
document.activeelement supported major browsers these days. if no element in focus activeelement return document body, so:
if (document.activeelement === document.body) { // nothing in focus }
Comments
Post a Comment