1function lengthInPageEncoding(s) {
2 var a = document.createElement('A');
3 a.href = '#' + s;
4 var sEncoded = a.href;
5 sEncoded = sEncoded.substring(sEncoded.indexOf('#') + 1);
6 var m = sEncoded.match(/%[0-9a-f]{2}/g);
7 return sEncoded.length - (m ? m.length * 2 : 0);
8}
9