Last active
December 2, 2015 10:10
-
-
Save mihailik/69e762837a4dc8276a2e to your computer and use it in GitHub Desktop.
disabling keyboard editing via keydown.preventDefault()
This file contains hidden or 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
<html> | |
<head><title>disabling keyboard editing via keydown.preventDefault()</title></head> | |
<body> | |
<h2>disabling keyboard editing via keydown.preventDefault()</h2> | |
<textarea id=txt></textarea> | |
<script> | |
window.onload = function() { | |
var txt = document.getElementById('txt'); | |
function handleCancelEvent(e) { | |
if (e.preventDefault) e.preventDefault(); | |
if (e.stopPropagation) e.stopPropagation(); | |
if (txt.value && txt.value != ',') { | |
if (txt.value != ';') | |
document.title = '['+txt.value+'] ' + (txt.value||'').length; | |
txt.value = ','; | |
} | |
else { | |
txt.value = ';'; | |
} | |
txt.selectionStart = txt.selectionEnd = 0; | |
txt.selectionStart = 1; | |
return false; | |
} | |
txt.onkeydown = txt.onkeyup = txt.onkeypress = handleCancelEvent; | |
if (txt.addEventListener) txt.addEventListener('compositionstart', handleCancelEvent, true); | |
if (txt.addEventListener) txt.addEventListener('compositionupdate', handleCancelEvent, true); | |
txt.focus(); | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment