码迷,mamicode.com
首页 > Web开发 > 详细

JS Encode and Decode URL

时间:2016-02-25 15:40:47      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/akwwl/p/5216835.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!