function CalByte() {
var curText;
var strLen;
var byteIs;
var lastByte;
var thisChar;
var escChar;
var curTotalMsg;
var okMsg;
var result = true;
curText = new String(document.sendform.msg.value);
strLen = curText.length;
byteIs = 0;
for(i=0; i<strLen; i++) {
thisChar = curText.charAt(i); escChar = escape(thisChar);
// ´,¨, ¸ : 2byte 임에도 브라우져에서 1byte로 계산
if (thisChar == "´" || thisChar == "¨" || thisChar == "¸" || thisChar == "§" ) {
byteIs++;
}
if (escChar.length > 4) {
byteIs += 2; //특수문자 한글인 경우.
} else if(thisChar != '\r') {
//개행을 제외한 이외의 경우
byteIs += 1;
}
if(byteIs > 80) {
alert('[안 내] 80byte를 초과하실 수 없습니다.');
thisText = curText.substring(0, i);
document.sendform.msg.value = thisText;
byteIs = lastByte; result = false;
break;
}
lastByte = byteIs;
}
curTotalMsg = Math.ceil(byteIs / 80); curEndByte = curTotalMsg * 80;
textlimit.innerText = byteIs; return result;
}
728x90
'Carpe Programming > javascript' 카테고리의 다른 글
| [cookie] beforeunload, 팝업 중복 체크 등 (0) | 2013.02.19 |
|---|---|
| [javascript] window.open 옵션 (0) | 2013.02.01 |
| [정규식] 정규식 정리 (0) | 2013.01.21 |
| ajax 전송 시 한글 깨짐 (0) | 2012.12.12 |
| 웹에서 한글(hwp) 파일 표출하기 (0) | 2012.12.11 |