Foreign Characters in Javascript Alert Showing Question Mark In Diamond

September 22nd, 2010 - Posted by Steve Marks to Javascript / jQuery, Web Development.

You include a foreign character, for example à è ç ü, to a Javascript alert popup and it comes out as a question mark in a black diamond as follows:

Foreign Characters being shown as black diamond

Does this sound familiar? If so, I know how frustrating this can be because it took me hours to find a way to resolve this.

The problem is that the characters in question do not fall within the encoding of your webpage set via the meta ‘Content-Type’ tag. For example, a webpage using the UTF-8 character set will not display these characters correctly.

The Solution

Lets imagine we are trying to alert Tämä Rocks (Finnish for ‘This Rocks’), if we were to alert it straight out as below we would get the issue:

alert("Tämä Rocks")

Instead, we need to use the hexadecimal equivalent prepended by ‘\x’ to get the characters to appear correctly as follows:

alert("T\xE4m\xE4 Rocks")

In doing this we now get the expected results:

For a full list of hexadecimal conversions visit

This entry was posted on Wednesday, September 22nd, 2010 at 7:43 pm by +Steve Marks and is filed under Javascript / jQuery, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (0)

No comments have been left yet. Be the first