Samuel Marks
Samuel Marks

Reputation: 1874

How do I encode a JavaScript file included in HTML? - I get `…` rather than `…`

Attempt:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <script type="application/javascript" charset="utf-8" src="/assets/first_scripts.js">
    </script>
</head>

view source

I also iconv -t utf-8'd the .js file. But both Firefox and Chrome show this character when I view source. On the render itself everything works; so no issue there; does this mean a bug in their source-code-viewer?

Upvotes: -2

Views: 48

Answers (1)

Nanigashi
Nanigashi

Reputation: 393

is Unicode/UTF-16 8230 (0x2026), which translates to UTF-8 [ 0xe2, 0x80, 0xa6 ].

Apparently the character is saved as UTF-8 on your server (localhost?), but the file is interpreted by something that isn't UTF-8-aware when it's served back to you. So each byte becomes an 8-bit (ISO-8859-1) character.

You could force the file to be ASCII-only by using String.fromCharCode(8230) or Unicode string literal '\u2026', instead of using the character string literal ('…').

Upvotes: 0

Related Questions