views:

255

answers:

1

I have a widget that people can put in their site.

The widget is generated via php script that echos the populated string using: document.write('$widget_output').

The hosting sites call to the widget using a javascript tag:

<script type="text/javascript" src="http://www.link.com/page.php?param=1"&gt;&lt;/script&gt;

The problem is that my widget is utf-8 and sometimes it's different from the sites hosting it, causing the widget to display gibberish text.

Does anybody have a way of fixing it so that it works in any circumstance?

Thanks!

+1  A: 

add a content-encoding http header (written quickly on my iPhone)

Let me explain it a bit further (writing on my laptop ;-). The browser requests different resources from servers. Every browser internally uses Unicode to represent data to display. Each resource coming from a web server (html page, javascript files, css files etc.) can optionally have encoding information attached in http header. If it has a content-encoding header, the browser converts the resource to the internal unicode representation using encoding from the response header. If there is no content-encoding header, the browser assumes, that the file encoding is the same as the page which requested the resource.

Concluding: If you have a script that is served from a web server and used on pages with different encoding, make sure that you add a content-encoding http header to that script.

qbeuek
Each page does have an http header, the problem is that some pages are not utf-8 encoded while some are. The widget is always utf-8 encoded.
rksprst
that shouldn't matter as long as the script is returned with appropriate content-encoding header
qbeuek