3

I got from server words which contains utf characters like Ž,ć and so on.... I put in url parameters and my url looks like ?id=229&name=%8eena%20mini%3f

I am fetching parameters from url with js function

function getURLParameter(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

and it parses first id parameter but on second (when I have utf before encoded in url) it breaks.

var id = getURLParameter('id');//works
var id = getURLParameter('name');//breaks when have utf

How to fetch that parameter when it has utf from url ? (On page I have <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">)

cmbuckley
  • 40,217
  • 9
  • 77
  • 91
Damir
  • 54,277
  • 94
  • 246
  • 365

1 Answers1

1

Whatever is encoding Žena to %8eena is not using UTF-8 encoding, it's using Windows-1252 enoding, since Ž is represented as 8e in that character set.

In UTF-8, Ž is represented as c5 bd, so you should expect your URL to contain %c5%bd if the form had the correct encoding.

Looks like you need <meta charset="utf-8"> on the previous page, or at the very least the attribute accept-charset="utf-8" on the form that you submit.

See also: Is there any benefit to adding accept-charset="UTF-8" to HTML forms, if the page is already in UTF-8?

Community
  • 1
  • 1
cmbuckley
  • 40,217
  • 9
  • 77
  • 91