Question

I've got a little problem with my code. In my website I got a search engine with filter option. The search condition are kept in window url, but the filter in standard does not take the search parameters.

I want to repair this problem.

I wrote simple JS code below:

var link = window.location.href;
var elementy = link.replace('+',' ').split('&');

So if I have url like this http://mywww.pl/searchcond=&cond1[somePolishCharHere]&cond1

and I use alert to show varible

alert(elementy[1]);

I expect to see 'cond1[somePolishCharHere]' but I've got 'cond1[someWirdStuffHere]'

Website has set UTF-8 encoding, and for e.q. if i make something like this:

var test = [poslishCharHere];
alert(test);

I got proper result ([poslishCharHere])

And I have no idea what is wrong...

Was it helpful?

Solution

var link = decodeURI( window.location.href );

For example

decodeURI("http://example.com/?foo=g%C4%99%C5%9B") === "http://example.com/?foo=gęś";

Edit: what you see in the browser's URL bar isn't always exactly what a valid URI should look like. The browser handles it transparently so the user can see readable text and type any character, but the character set in a valid URI is very limited (digits, letters and a few symbols), and everything else needs to be encoded using "percent encoding". https://www.rfc-editor.org/rfc/rfc3986#section-2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top