/**
* 判断一个url字符串的字节长度是否过长。
*
* Parameters:
* url - {String} url字符串。
*
* Returns:
* {Boolean} url字符串的字节长度是否过长。
*/
function urlIsLong(url){
//当前url的字节长度。
var totalLength = 0,
charCode = null;
for (var i=0, len=url.length; i<len; i++) {
//转化为Unicode编码
charCode = url.charCodeAt(i);
if (charCode < 0x007f) {
totalLength++;
} else if ((0x0080 <= charCode) && (charCode <= 0x07ff)) {
totalLength += 2;
} else if ((0x0800 <= charCode) && (charCode <= 0xffff)) {
totalLength += 3;
}
}
return (totalLength < 2000) ? false : true;
};
判断一个url字符串的字节长度是否过长
最新推荐文章于 2021-02-13 01:11:11 发布