简体   繁体   English

window.location.href或$(location).attr('href')和波兰变音符号

[英]window.location.href or $(location).attr('href') and Polish diacritics

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. 搜索条件保存在窗口URL中,但标准中的过滤器不采用搜索参数。

I want to repair this problem. 我想修复这个问题。

I wrote simple JS code below: 我在下面编写了简单的JS代码:

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

So if I have url like this http://mywww.pl/searchcond=&cond1[somePolishCharHere]&cond1 所以,如果我有这样的网址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]' 我希望看到'cond1 [somePolishCharHere''但我有'cond1 [someWirdStuffHere]'

Website has set UTF-8 encoding, and for eq if i make something like this: 网站设置了UTF-8编码,对于eq,如果我做了这样的事情:

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

I got proper result ([poslishCharHere]) 我得到了正确的结果([poslishCharHere])

And I have no idea what is wrong... 我不知道出了什么问题......

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. 编辑:您在浏览器的URL栏中看到的内容并不总是有效的URI应该是什么样子。 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". 浏览器透明地处理它,以便用户可以看到可读文本并键入任何字符,但有效URI中的字符集非常有限(数字,字母和几个符号),其他所有内容都需要使用“百分比编码”进行编码。 http://tools.ietf.org/html/rfc3986#section-2 http://tools.ietf.org/html/rfc3986#section-2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM