|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
How can I detect the encoding of a referring page?
I have a page that is charset=windows-1255 that pulls an external JavaScript file. I need this JavaScript file to be able to detect what encoding the first page is in and display itself accordingly (have the JavaScript file dynamically be in the same encoding as the page that it is in). I'm guessing that Google Adsense do this since you can paste your Google Adsense code in pages with different encodings and the Google ads will be displayed properly (and even display ads in different languages). TIA! |
|
|||
|
Hello Gyumal,
How could a JavaScript file (or any other file) dynamically change it's encoding, even if you have that information? Google is using an iframe, and the text in that iframe can have a different encoding than the referring file, so there is no dependency. Perhaps that is a solution for you too. best regards - Sam
__________________
Software-Pointers.com - Directory of Software Development Sites - Free submission. |
|
|||
|
The encoding of a page can be determined in an HTTP header.
If I can know the encoding of the referring page I can create the JavaScript dynamically in the correct encoding and "tell" the browser what encoding I am using via the HTTP header. |
|
|||
|
In that case, you would need the script that generates the JavaScript to know the encoding. You could get that via a HTTP request, but the information you get in the header (if any) is often wrong, because the server itself typically doesn't know what the encoding is. So you could fetch the page, any parse it for a charset information in the HTML header. Not efficient and error-prune, but I can't think of anything else.
Sam
__________________
Software-Pointers.com - Directory of Software Development Sites - Free submission. |
|
|||
|
Good thinking, guymal. Now I understand your original question better.
There is the document.charset property in JavaScript, but it is not supported by Firefox, and probably a few other browsers, only IE. I don't think there is an equivalent for non-IE browsers. - Sam
__________________
Software-Pointers.com - Directory of Software Development Sites - Free submission. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |