V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
reorx
V2EX  ›  问与答

javascript, simulate keyboard events, work on chrome(webkit)

  •  
  •   reorx · 2011-01-31 08:25:54 +08:00 · 4001 次点击
    这是一个创建于 4849 天前的主题,其中的信息可能已经有所发展或是发生改变。
    in FF, i've used this code:

    74 if (keyCount == lineLimit) {
    75 // method in FF, no Chrome
    76 var mock = document.createEvent("KeyboardEvent"); // or KeysEvent
    77 mock.initKeyEvent("keypress",true,true,null,false,false,false,false,14,0);
    78 var x = document.getElementById('InputCategory');
    79 // rise height before Enter
    80 $(this).height(div_height + font_height + offset_height);
    81 // mock Enter
    82 x.dispatchEvent(mock);
    83 // init keyCount
    84 keyCount = 0;
    85 }

    it works, but could not be effective on webkit-based browsers like chrome.

    so i asked google and found keyboard event is one of the DOM Level 3 events,here is an aticle: http://www.w3.org/TR/DOM-Level-3-Events/

    then i knew /* initKeyboardEvent */ is not supported on chrome & safari, /* initUIEvent */ i've tried, it didn't work also.

    Do virtual keyboard events reall can be simulated on chrome ? plesase help me :)
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5549 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 07:31 · PVG 15:31 · LAX 00:31 · JFK 03:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.