How to fix encoding problem in javascript?

6

I'm running the code below:

alert('Não é possível realizar essa operação sem a seleção de uma banca.');

But it's popping up like this:

    
asked by anonymous 27.02.2014 / 14:42

3 answers

5

The problem is not the JavaScript encode, but the page encode. Try to use <meta charset="utf-8" /> in your head section:

<html lang="pt-br">
<head>
    <meta charset="utf-8" />

Use this tag shortly after opening head , even before title . Depending on the stage of your project and how it was configured, it may be that charset is not utf-8 , but iso-8859-1

    
27.02.2014 / 14:46
5

Check in your text editor or ide, which is the default coding type for new files, after checking you will see that it should be UTF-8 or iso-8859-1 < (also called Windows-1252 at times). If the file already exists, you can check the encoding through the footer in Notepad ++ .

Use the meta tag for each case:

html5

<meta charset="utf-8" />

html4.x

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

You should use UTF-8 or iso-8859-1

    
27.02.2014 / 14:54
4

When this occurs:

  • I open the file in Notepad ++ and convert to UTF-8
  • I make sure the page has the header <meta charset="utf-8"> .
  • Resolve in 90% of cases.

        
    27.02.2014 / 14:47