e.preventDefault(); behaviour not working in Firefox?

后端 未结 1 962
無奈伤痛
無奈伤痛 2021-01-23 19:14

I have this basic function for handling the key event, everything works great. However, in Firefox 9.0.1 it seems I can\'t prevent the default event which is showing of bookmark

相关标签:
1条回答
  • 2021-01-23 19:46

    Seems like some sort of bug regarding alert. Try this:

    $(document).keydown(function(evt) {     
        if (evt.which == 66 && evt.ctrlKey) {                             
             if (evt.preventDefault) {
                 evt.preventDefault();
             } else {
                 evt.returnValue = false;
             }    
             console.log("Ctrl+B pressed");
             return false;                      
        }
    });
    

    Doesn't open the Bookmarks Toolbar for me now. I assume you don't actually want to alert do you? I think you can just call your method as long as it doesn't contain an alert.

    0 讨论(0)
提交回复
热议问题