I have a Javascript bookmarklet that uses encodeURIcomponent
to pass the URL of the current page to the server side, and then use urldecode
on the server side to get the characters back.
The problem is, when the encoded character is not in utf-8 (for my case it's gb2312, but it could be something else), and when the server does the urldecode
, the decoded character become squares. Which, obviously, isn't what it looked like before the encoding.
It's a bookmarklet, input could be anything, so I can't just define "encode as gb2312" in the js, or "decode as gb2312" in the php scripts.
So, is there a correct way of using encodeURIcomponent
which passes the character encoding together with the contents, and then the decoding can pick the right encoding to decode it?