vishnu
vishnu

Reputation: 11

How to display arabic in Javascript?

I am using utf-8 in my jsp page. I have set the page pageEncoding="UTF-8" contentType="text/html;"

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

But when i try to alert a UTF-8 value then its coming as same utf-8 characters.

Upvotes: 1

Views: 7122

Answers (2)

user213154
user213154

Reputation:

If the page is properly encoded UTF-8 then my first guess is that the HTTP headers are indicating something other than UTF-8. HTTP headers override <meta http-equiv, read HTML 4.01 here.

Check in a browser the exact HTTP response headers. If there is an inappropriate Content-Type header, change it. If there is none, add one.

Upvotes: 0

mplungjan
mplungjan

Reputation: 177940

But is the DATA on the page UTF-8 too? If you set the page to UTF-8 but load data which is for example Windows 1256, you will not see Arabic at all

If your issue is alert('Something Arabic here') you may want to use entities

Here is a good explanation http://www.w3.org/International/tutorials/bidi-xhtml/

Here is a few methods (perhaps not THE methods):

alert(document.getElementBzId('hiddenDiv').innerHTML)

where you have

<div id="hiddenDiv" style="display:none">&#1575;&#1587;&#1578;&#1605;&#1575;&#1585;&#1577; &#1591;&#1604;&#1576; &#1578;&#1608;&#1592;&#1610;&#1601;</div>

the other one is creating it dynamically

<script>
var alertString = "&#1575;&#1587;&#1578;&#1605;&#1575;&#1585;&#1577;&#1591;&#1604;&#1576; &#1578;&#1608;&#1592;&#1610;&#1601;" 
var d = document.createElement('div');
d.innerHTML=alertString;
alert(d.innerHTML)
</script>

Upvotes: 1

Related Questions