开发者

Cyrillic URLs in Google Chrome?

开发者 https://www.devze.com 2023-02-21 08:20 出处:网络
I\'m having troubles with cyrillic URLs in my site. Well, I change my URLs with Javascript (jQuery) and cyrillic characters work fine in every browser instead Google Chrome, where it\'s shown thir uni

I'm having troubles with cyrillic URLs in my site. Well, I change my URLs with Javascript (jQuery) and cyrillic characters work fine in every browser instead Google Chrome, where it's shown thir unicodes. I thought that the URLs wasnt decoded, so I tried one Javascript function to decode them to a normal format but nothing has changed. So any ideas how to solve this problem?

My URL is something like that:

http://site.com/index.html#начало

But in GC is sho开发者_StackOverflow社区wn like that:

http://site.com/index.html#%D0%BD%D0%B0%D1%87%D0%B0%D0%BB%D0%BE

Any help?


It is not only Chrome, if you would paste your URl directly (or as a bookmark..) into IE8 it can also cause problems.

An URL (by specification) cannot contain cyrillics. We used to have them but got rid off them, too many issues.

see also: URL with Cyrrilic querystring not working in IE (but working in Firefox)


Try using functions like rawurlencode() and rawurldecode().

Example:

   $url = "http://site.com/index.html";
   $url_suffix = "#начало";

   $url_enc = $url . rawurlencode($url_suffix);
   echo "$url_enc<br />";

   $url_dec = rawurldecode($url_enc);
   echo "$url_dec<br />";

Output (In browser):

http://site.com/index.html%23%D0%BD%D0%B0%D1%87%D0%B0%D0%BB%D0%BE
http://site.com/index.html#начало

rawurlencode() and rawurldecode() are safe if you try send parameter like email address using GETs (urlencode() and urldecode() are not).

Also set your page meta like this

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


In Chrome, what works for me is use decodeURIComponent (native function) when getting the url. Something like this:

decodeURIComponent(window.location.href)

Going to an encoded url will just work then.


Google Chrome always encode his urls, but it does not let it slip.
Try this out: COPY URL extension
You can open source code and see how it works.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号