简体   繁体   中英

onfocus event triggered multiple times in Internet explorer

The code is to add some access keys to some buttons present on the page. The interface is like this: main page with some accordion tabs lets say accordion_A , accordion_B and accordion_C, there is a button A in let us say 'accordion_A' tab, for that button A , a hot key(for example: ALT+D) is added so pressing that will invoke that button associated function.

    if ( _browser.isIE )
        text += " href='javascript:void(0)'" +
                " onfocus='KeyPressed(\"" + key + "\")'></A>";
     else
        text += " href='Javascript:KeyPressed(\"" + key + "\")'></A>";

First the page is opened and let us suppose accordion_C is the default tab, now I go to accordion_A, now the hotkeys are added to the buttons present on accordion_A (deferred tab). Now I again go back to accordion_C and press 'ALT+D' to invoke the button present on accordion_A. The button function invokes and a popup is opened. The problem starts here, in IE when I close the popup, again the onfocus event is triggered, this will go on for like forever.

Is there any way to counter this phenomenon, Thanks for reading, hoping i am clear.

Try adding this inside your KeyPressed function

 event.cancelBubble = true;
 if (event.stopPropagation) event.stopPropagation();   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM