Is it possible to prevent Chrome from appearing in an infinite loop when displaying focus event warnings without disabling and re-enabling the event?

Consider the following code. If I press cmbMonkeys, it causes an endless loop of warning messages in Google Chrome. My workaround for cmbPeople is working fine. Does anyone know of a different way to prevent endless loops when displaying warnings about focus or blur events without disabling and re-enabling the event?

<html> <head> <script> var eventHandler; function cmbPeople_OnFocusHandler() { alert("focus"); } function cmbPeople_CallFocusHandler(control) { eventHandler = control.onfocus; control.onfocus = null; cmbPeople_OnFocusHandler(); } function cmbPeople_CallBlurHandler(control) { control.onfocus = eventHandler; } function cmbMonkeys_FocusHandler(control) { alert("I like monkeys"); } </script> </head> <body> monkeys <select id="cmbMonkeys" onfocus="cmbMonkeys_FocusHandler(this)"></select> people <select id="cmbPeople" onfocus="cmbPeople_CallFocusHandler(this)" onblur="cmbPeople_CallBlurHandler(this)"></select> </body> </html> 
+4
source share
1 answer

With a simple state handler, maybe?

 var isFocus = false; function cmbPeople_CallFocusHandler(control) { if(!focus){ focus = true; cmbPeople_OnFocusHandler(); } } function cmbPeople_CallBlurHandler(){ isFocus = false; } 
+4
source

All Articles