Javascript Management

Is there any way to determine the current focused control on a web page? I want to keep focused control before my ajax callback and restore it afterwards.

Can this be easily identified?

Thanks,

Aj

+4
source share
4 answers

Using:

document.activeElement 

This is not officially standardized ( it will be in HTML5 ), but most, if not all, support its modern browsers. It started in Internet Explorer so that all versions of IE support it. Firefox supports it with FF3. Chrome also supports it, and I assume that Safari too.

+3
source

Many browsers now support document.activeElement .

Works in:

  • Firefox
  • IE 6,7,8
  • Chrome
  • Safari
  • Opera
+1
source

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(); 
+1
source

Try using document.activeElement .

+1
source

Source: https://habr.com/ru/post/1300663/


All Articles