Is there any way I can determine the currently focused control on a web page? I wish to save the focused control before my ajax callback and restore it afterwards.
Can this be easily determined?
Thanks,
AJ
Is there any way I can determine the currently focused control on a web page? I wish to save the focused control before my ajax callback and restore it afterwards.
Can this be easily determined?
Thanks,
AJ
Many browsers now support document.activeElement
.
Works in:
If you are using jQuery you can solve this with the http://plugins.jquery.com/project/focused plugin
// elm is the DOM Element owning the focus or null if no
// DOM Element has the focus
var elm = jQuery.focused();
Use:
document.activeElement
This has not been officially standardized yet (it will be in HTML5), but most, if not all, modern browsers support it. It started in Internet Explorer so all versions of IE will support it. Firefox has supported it since FF3. Chrome also supports it and I assume Safari does as well.