initKeyEvent keypress only works in FireFox. need a cross browser solution!

前端 未结 2 605
北荒
北荒 2020-12-11 05:49

This is my code:



        
相关标签:
2条回答
  • For Webkit-based browsers (Safari/Chrome), the event initialization call should look a bit differently (see https://bugs.webkit.org/show_bug.cgi?id=13368):

    initKeyboardEvent(in DOMString typeArg, 
                      in boolean canBubbleArg, 
                      in boolean cancelableArg, 
                      in views::AbstractView viewArg, 
                      in DOMString keyIdentifierArg, 
                      in unsigned long keyLocationArg, 
                      in boolean ctrlKeyArg, 
                      in boolean shiftKeyArg, 
                      in boolean altKeyArg, 
                      in boolean metaKeyArg, 
                      in boolean altGraphKeyArg);
    
    0 讨论(0)
  • 2020-12-11 06:41

    To add to Alexander's response:

    There is a webkit bug that keyboard events initialized using initKeyboardEvent get an incorrect keyCode and charCode of 0: https://bugs.webkit.org/show_bug.cgi?id=16735

    A working solution for this is posted in this SO answer.

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