当前位置 博文首页 > BossZhou_的博客:JS加密/解密 URI和URL的关系
在js里对路径、参数进行加密解密的常用方法encodeURIComponent()/decodeURIComponent()
encodeURIComponent(URIstring)
<script type="text/javascript">
document.write(encodeURIComponent("http://www.w3school.com.cn"))
document.write("<br />")
document.write(encodeURIComponent("http://www.w3school.com.cn/p 1/"))
document.write("<br />")
document.write(encodeURIComponent(",/?:@&=+$#"))
</script>
decodeURIComponent(URIstring)
<script type="text/javascript">
var test1="http://www.w3school.com.cn/My first/"
document.write(encodeURIComponent(test1)+ "<br />")
document.write(decodeURIComponent(test1))
</script>
输出:
http%3A%2F%2Fwww.w3school.com.cn%2FMy%20first%2F
http://www.w3school.com.cn/My first/
HTTP = Hyper Text Transfer Protocol
URI = Universal Resource Identifier
URL = Universal Resource Locator
一句话解释:URI 和 URL 都定义了 what the resource is。URL 还定义了 how to get the resource。
URI是用来标识网上的资源的
URI分为URL和URN这两大类。
URL与URN的不同之处在于前者不仅标识资源,而且还指出了访问资源的方式。比如采用何种协议(http,ftp…),而URN则没有。
原文链接:URI/URL
cs