html5 - execCommand doesn't fire when called from keydown event in Windows Store apps -
i'm writing windows store app (html) includes simple rich-text editing. can apply bold selected using button fires document.execcommand("bold",false,null);
however when bind keydown event ctrl+b, nothing happens. here's keydown code.
document.addeventlistener("keydown", catchshortcuts, false); function catchshortcuts(e) { if (e.ctrlkey) { if (e.keycode == 66) // b document.execcommand('bold', true, null); } } }
i know keydown code works fine because if replace document.execcommand
line of code fires fine when press ctrl+b. seems execcommand has problem keydown event?
turns out works fine if use keypress instead of keydown. in case else has same issue, that's workaround. still not sure why onkeydown doesn't work though.
working code:
document.addeventlistener("keypress", catchshortcuts, false); function catchshortcuts(e) { if (e.ctrlkey) { if (e.keycode == 66) // b document.execcommand('bold', true, null); } } }
Comments
Post a Comment