iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
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

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-30-2006, 05:20 AM
WebProWorld New Member
 
Join Date: Aug 2003
Posts: 10
guymal RepRank 0
Default Detecting Referring Page Encoding

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!
Reply With Quote
  #2 (permalink)  
Old 03-30-2006, 05:23 PM
WebProWorld Member
 
Join Date: Nov 2004
Posts: 33
imported__sam_ RepRank 0
Default Re: Detecting Referring Page Encoding

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.
Reply With Quote
  #3 (permalink)  
Old 03-31-2006, 07:15 PM
WebProWorld New Member
 
Join Date: Aug 2003
Posts: 10
guymal RepRank 0
Default

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.
Reply With Quote
  #4 (permalink)  
Old 04-01-2006, 10:29 AM
WebProWorld Member
 
Join Date: Nov 2004
Posts: 33
imported__sam_ RepRank 0
Default

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.
Reply With Quote
  #5 (permalink)  
Old 04-04-2006, 04:19 AM
WebProWorld New Member
 
Join Date: Aug 2003
Posts: 10
guymal RepRank 0
Default

So maybe I could detect the current page's encoding via JavaScript in the referring page and send that in the request for the JavaScript file?
Reply With Quote
  #6 (permalink)  
Old 04-04-2006, 06:36 PM
WebProWorld Member
 
Join Date: Nov 2004
Posts: 33
imported__sam_ RepRank 0
Default

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.
Reply With Quote
  #7 (permalink)  
Old 04-10-2006, 04:48 AM
WebProWorld New Member
 
Join Date: Aug 2003
Posts: 10
guymal RepRank 0
Default

In Firefox I discovered document.characterSet but I'm not sure about other browsers.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 12:41 PM.



Search Engine Optimization by vBSEO 3.3.0