Character encoding problem - cross-domain scripting

I have an Asp.Net web application whose users include a script tag in their web page and get data from my server (using JsonP and a common handler (ashx))

The data is in Hebrew and I have given utf-8 encoding in the response.

When the client's website (which displays data) is using "windows-1255", I cannot see the text correctly.

script can be included in any web page with any character set.

Do I need to transform my data or set the charset property of the response differently?

Thanks Yaron

+2


source to share


2 answers


When the client's website (which displays the data) is using "windows-1255", I cannot see the text correctly.

Yes. Here: when serving <script>

you can set the "charset" parameter in the Content-Type response to whatever you like, but IE will ignore you and use the original page's encoding instead. (Maybe some other browsers do too.)



So, if you are using JSONP or another script -tag tool to pull data, that data must be either in the same encoding as the original page, or in plain ASCII. If you provide an external service for many web pages in different encodings, you should stick with ASCII.

This means that your JSON encoder must convert all non-ASCII characters to string literals to their hidden form from JS, for example \u20AC

instead of raw.

+3


source


It is probably best if you make it clear to your clients that your interface is using UTF-8 encoding. When they redirect your data to their clients, they should set Response.CharSet

to UTF-8. Surely you are already doing this at your end?



+1


source







All Articles