<script type="text/javascript">function cancelSpace(e){
var e = e || window.event;
var elm = e.srcElement || e.target;
var key = e.keyCode || e.charCode;
if(key == 32){
if(elm.tagName.toLowerCase()=="input" && elm.type.toLowerCase()=="text" || elm.tagName.toLowerCase() == "textarea"){
return;
}
if(window.event){
e.returnValue = false;
}
else{
e.preventDefault();
}
}
}
document.onkeypress=cancelSpace;
</script>
Author: Xuan
Copyright: CC BY-NC-SA 4.0