javascript - Why <a> tag replaces spaces with %2520? how to solve the issue? -


in case, suppose explaining problem scenario best way explain it.

i have search box in page called a.html, parameters passed page should replaced value of search box. problem that, when pass parameters spaces replaced %2520 therefore wrong value added search box. need solve it.

  1. <a href="www.example.com/a.html?value=here , there">link</a>

  2. following address put address bar: www.example.com/a.html?value=here%2520and%2520there

  3. this value replaced value of search box: here%2520and%2520there. need have value "here , there" in search box. (without %2520)

what seems have happened here url double encoded (see below); while can't explain why happens, may because url not url encoded:

<a href="www.example.com/a.html?value=here , there">link</a> 

it should be:

<a href="www.example.com/a.html?value=here+and+there">link</a> 

or:

<a href="www.example.com/a.html?value=here%20and%20there">link</a> 

double encoding goes this:

" "      regular space "%20"    percent encoded, " " -> "%20" "%2520"  percent encoded, "%" -> "%25" 

update

the reason couldn't explain double encoding because question missing how passed value added search box. scenario search box populated percent encoded value. fix that, have decode value first, i.e.

searchbox.value = decodeuricomponent('here%20and%20there'); 

see also: decodeuricomponent()


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -