Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decode parameter with space in URL using javascript?

I try to extract parameter from URL, but one parameter has space which is replaced with "+", so the parameter I extract is "iphone+4", but actually it is "iphone 4", how can I convert to the second form, decodeURIComponent does not work here.

like image 776
zjffdu Avatar asked Dec 16 '22 15:12

zjffdu


2 Answers

function decodeParameter(param) {
   return decodeURIComponent(param.replace(/\+/g, ' '));
}
like image 74
gion_13 Avatar answered Dec 21 '22 22:12

gion_13


"iPhone+4".replace("+"," ");  

That should do it?

like image 33
Thor Jacobsen Avatar answered Dec 21 '22 22:12

Thor Jacobsen