JS Encode and Decode URL
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS Encode and Decode URL相关的知识,希望对你有一定的参考价值。
1.Encode URL String
var url = $(location).attr(‘href‘); //get current url //OR var url = ‘folder/index.html?param=#23dd&noob=yes‘; //or specify one var encodedUrl = encodeURIComponent(url); console.log(encodedUrl); //outputs folder%2Findex.html%3Fparam%3D%2323dd%26noob%3Dyes
2.Decode URL String
var url = $(location).attr(‘href‘); //get current url //OR var url = ‘folder%2Findex.html%3Fparam%3D%2323dd%26noob%3Dyes‘; //or specify one var decodedUrl = decodeURIComponent(url); console.log(decodedUrl); //outputs folder/index.html?param=#23dd&noob=yes
3.HTML URL Endoding References
space %20 ! %21 " %22 # %23 $ %24 % %25 & %26 ‘ %27 ( %28 ) %29 * %2A + %2B , %2C - %2D . %2E / %2F ... etc
测试网址:http://www.w3schools.com/tags/ref_urlencode.asp
原文网址:http://www.sitepoint.com/jquery-decode-url-string/
以上是关于JS Encode and Decode URL的主要内容,如果未能解决你的问题,请参考以下文章
535. Encode and Decode TinyURL
535. Encode and Decode TinyURL
Leetcode 535: Encode and Decode TinyURL