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

2011-01-31 08:25:54 +08:00
 reorx
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 :)
4075 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/7902

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX