20

I want to show log message in arabic language using JavaScript alert() function, for which I code:

alert('أدخل سعر الافتتاح');

which means

alert('Enter opening price');

but when i save the .js file Dreamweaver says enter image description here

and if I run the script browser says

enter image description here

this page contains

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

and i am using a lot of text in arabic which works fine.

now how can I use alert for different language?

1
  • 7
    This question has nothing to do with JavaScript or HTML, but with your IDE. There should be an option in it to set the encoding to UTF-8. Commented Mar 24, 2012 at 16:44

11 Answers 11

52

just add your script like this:

<script src="/js/intlTelInput.min.js" charset="utf-8"></script>
Sign up to request clarification or add additional context in comments.

1 Comment

this was the solution to the problem (diacritics used in a source .js file)
26

Just like any other text file, .js files have specific encodings they are saved in. This message means you are saving the .js file with a non-UTF8 encoding (probably ASCII), and so your non-ASCII characters never even make it to the disk.

That is, the problem is not at the level of HTML or <meta charset> or Content-Type headers, but instead a very basic issue of how your text file is saved to disk.

To fix this, you'll need to change the encoding that Dreamweaver saves files in. It looks like this page outlines how to do so; choose UTF8 without saving a Byte Order Mark (BOM). This Super User answer (to a somewhat-related question) even includes screenshots.

1 Comment

IMPORTANT: "... choose UTF8 WITHOUT saving a Byte Order Mark (BOM)"
7

Try to put in the head section of your html the following:

<meta charset='utf-8'>

I think this need to be the fist in head section. More information about charset: Meta Charset

1 Comment

page already have <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> and i am using a lot of text in arabic which works fine..
3

I think you just need to make

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

Before calling your .js files or code

Comments

2

Same problem here, solved with this: In Eclipse (with .js file open and on focus), go to, "File", "Properties", "Resource", "Text file encoding" choose "Other:" UTF-8, put correct characters code inside the code save your file and you are done!

Comments

2

For others, I just had a similar problem and had to copy all code from my file, put it to simple notepad, save it with utf-8 coding and then replace my original file.

The problem at my side was caused by using PSpad editor.

1 Comment

#eservices.tamin.ir
1

The encoding for the page is not set correctly. Either add a header

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

or use set the appropriate http header.

Content-Type:text/html; charset=UTF-8

Firefox also allows you to change the encoding in View -> Character encoding.

If that's ok, I think javascript should handle UTF8 just fine.

1 Comment

page already have <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> and i am using a lot of text in arabic which works fine..
1

This is a quite old request to reply but I want to give a short answer for newcommers. I had the same problem while working on an eight-languaged site. The problem is IDE based. The solution is to use Komodo Edit as code-editor. I tried many editors until I found one which doesnt change charset-settings of my pages. Dreamweaver (or almost all of others) change all pages code-page/charset settings whenever you change it for page. When you have changes in more than one page and have changed charset of any file then clicked "Save all", all open pages (including unchanged but assumed changed by editor because of charset) are silently re-assigned the new charset and all mismatching pages are broken down. I lost months on re-translating messages again and again until I discovered that Komodo Edit keeps settings separately for each file.

1 Comment

My notepad++ editor setting was causing the same problem. The moment I changed it to Encode in utf-8 , it was gone! Thank you!
0

I too had this issue, I would copy the whole piece of code and put in Notepad, before pasting in Notepad, make sure you save the file type as ALL files and save the doc as utf-8 format. then you can paste your code and run, It should work. ?????? obiviously means unreadable characters.

Comments

0

I found out that sometimes the javascript engine only believes it is utf-8 in the presence of the UNICODE BOM in the js file.

Tip: Some editors like geany allows to generate BOM which are 3 bytes in the beginning of the file. They are invisible in most editors, but you can see them in vim, 3 special chars in the 0:0 position.

Just for information: the bytes value is 0xEFBBBF indicating that is a serious utf-8 file.

One workaround is to use all special chars in javscript as \xHH (hexa) format, but that's a little too geeky, you have to know the equivalents.

// Try in the console, a Brazilian word:
alert( 'Cora\xE7\xE3\x6F' );

1 Comment

The JS engine won't care. It's more likely the BOM affected your server file type detection, causing it to be served with the correct HTTP header.
-1

I found a solution to my problem that seems like yours.

For some reason a script called from a external file doesn't works with charset="UTF-8", instead i had to use charset="ISO-8859-1" into script tag.

Now I'm after the "why it works?" reason.

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
This answer applies only when your script file is saved as ISO-8859-1. It should be saved (and served) as UTF-8 instead, then the <script> tag will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.