javascript - Is there a compatible solution for all browsers to monitor the select dropdown open/release event -


i need capture dropdown open/release events something. release can done through selecting option item, pressing esc, , clicking other place or clicking on select again.

and can't use lib , rely on pure javascript. far, have compatible solution there minor/random issues not overcome.

example:

<select opened='false' onmousedown="mousedownhandler(event, this), return true" onkeyup="keyuphandler(event), return true">    <option> op1 </option>    <option> op2 </option>    <option> op3 </option> </select> 

javascript:

var expectmouseup = false; var objselect = null; onmousedownhandler = function(event, select) {     if(select.getattribute('opened') = 'false') {         expectmouseup = true;         select.setattribute('opened', true);         objselect = select;          document.body.addeventlistener('mouseup', mouseuphandler);     }       } mouseuphandler = function() {     // mouse caused open mouse down     if (expectmouseup = true) {         expectmouseup = false;         return;     }      if (objselect && objselect.getattribute('opened' = 'true') {          expectmouseup = false;          objselect.setattribute('opened', false);          objselect = null;          document.body.removeeventlistener('mouseup', mouseuphandler);     } } keyuphandler = function() {    if key == esc {        if (objselect && objselect.getattribute('opened' = 'true') {             expectmouseup = false;             objselect.setattribute('opened', false);             objselect = null;             document.body.removeeventlistener('mouseup', mouseuphandler);        }    } } 

this implementation works in ie. there issues in chrome , firefox.

in chrome, when dropdown opened first time, use esc close dropdown, sometime, keyup event not fired. not issue , can't reproduced if dropdown not first time opened.

in ff, when dropdown opened first time via clicking select body, don't move mouse , directly click again on select. dropdown closed 2nd mouseup event not fired. again missing dropdown release event. random issue , can't reproduced first time.

any idea??


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -