url中的编码问题

133 阅读1分钟

url中的编码问题

URI中包含的字符类型

  1. 保留字符

    ;/?:&=+$

  2. 非转义字符

    52个字母(大写加小写)

    10个数字

    8个uri标记符 - _ . ! ~ * ` ( )

  3. 其他字符

  4. 被转义字符

  • encodeURI/decodeURI
    1. 操作对象是整个url
    2. encodeURI转义对象是其他字符
  • encodeURIComponent/decodeURIComponent
    1. 操作对象是组成url的一部分。
    2. encodeURIComponent转义对象是 保留字符,#,其他字符
    3. decodeURIComponent反转义对象是 保留字符,非转义字符,#,其他字符
  • escape/unescape
    1. 支持度不高,常用来客户端之间的编码。

所以encodeURIComponent/decodeURIComponent还适合url参数值是url地址的形式

例如 url=www.xx.cn/index.html?… 这种形式