Created
August 3, 2013 06:49
-
-
Save NdYAG/6145500 to your computer and use it in GitHub Desktop.
Get the character user input in input[type="text"] bypassing IME
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getCaretPos(input_node) { | |
return 'selectionStart' in input_node? input_node.selectionStart: Math.abs(document.selection.createRange().moveStart('character', -input_node.value.length)) | |
} | |
function getCaretText(input_node) { | |
var pos = getCaretPos(input_node) | |
if(!pos) return | |
return input_node.value.substring(pos - 1, pos) | |
} | |
$input_node.on('keyup', function() { | |
dosomething(getCaretText($input_node[0])) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment