escape() function fixes ASCII characters that are not valid for use in URLs, but does not handle unicode characters well. To make matters worse, there were browser incompatibilities: using
escape() in IE would generate a new string that looked like %unnnn, where n is a hexadecimal digit. The correct encoding should follow RFC 2279 and be a set of hexadecimal digit pairs like %nn%nn. Netscape 4 would just treat the characters as ASCII, which would result in lost accents and umlauts.
The following form uses either the built-in browser function
encodeURIComponent() or a created one
encodeURIComponentNew() to properly escape characters for use in the URL.
encodeURIComponentNew() function always encodes to UTF-8, regardless of the charset specified by the page. This may be desirable behavior, even for browsers that have a built-in function.
Copyright © 2000-2010 Tim Powell
All rights reserved.