javascript - Why bootstrap dropdown calling window.onfocus -
when click on bootstrap dropdown link, custom set window.onfocus
gets called.
why bootstrap calling window.onfocus
method?
<ul class="nav navbar-nav navbar-right"> <li data-ng-show="username" class=""> <a href="javascript://" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">name<span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="#">logout</a></li> </ul> </li> </ul>
window.onfocus = function() { alert("window onfocus called"); }
when click on menu, alert message shown.
because bootstrap triggers focus
event on dropdown anchor clicked. event naturally bubbles dom tree until reaches window, , functionality invoked.
you can prevent this, using event.stoppropagation()
:
jquery(function($){ $('.dropdown-toggle').focus(function(e){ e.stoppropagation(); }); });
Comments
Post a Comment