开发者

How to display arabic in Javascript?

I am usi开发者_如何学Cng 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.


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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜