Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable UTF-8 encoding for JavaScript

I don't know how should I titled this question but hope my friends will understand the problem and will help me :)

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?

like image 216
PHP Ferrari Avatar asked Mar 24 '12 16:03

PHP Ferrari


3 Answers

just add your script like this:

<script src="/js/intlTelInput.min.js" charset="utf-8"></script>
like image 98
Vladimir Starkov Avatar answered Nov 07 '22 17:11

Vladimir Starkov


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.

like image 20
Domenic Avatar answered Nov 07 '22 17:11

Domenic


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

like image 6
Vitor Canova Avatar answered Nov 07 '22 17:11

Vitor Canova