What is the best way to accent words in .js files?

3

Is there a way to write words the way they are, with their accents?

In php, just use:

<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />

In javascript, the word Informação must be written Informa\u00e7\u00e3o .

Is there an alternative?

    
asked by anonymous 04.01.2016 / 18:36

1 answer

4

Set up your text editor (notepad ++, sublime, etc.) to save edits as UTF-8 or charset that you find most appropriate for you.

It is recommended to use a multibyte character set such as UTF-8 (No BOM).

Loading .js files

When loading a JavasScript file, it is also recommended to specify the charset used:

<script src="file.js" charset="utf-8"></script>

Specify the meta tag

In HTML, obviously specify the meta tag:

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

The entire environment should be well configured.

If you are using PHP , specify the header:

header('Content-Type: text/html; charset=UTF-8');

Notes:

  • The <meta> tag is unrelated to PHP. It's from HTML.

  • This answer addresses the use of UTF-8, however, it does not necessarily mean that it is the best form or final solution. Using UTF-8 is a recommendation to make your application's charset internationalized because UTF-8 supports multibyte characters.

  • 04.01.2016 / 19:18