There are several pages of html in different encoding (utf-8 / windows-1251). The following code is placed on them to load the javascript code (in utf-8):

help_url="http://eodiwojeidjweo.ru/chat_client/"; var hcc = document.createElement("script"); hcc.type ="text/javascript"; hcc.charset="windows-1251"; hcc.async =true; hcc.src =help_url+"chat_client.js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hcc, s.nextSibling); 

But! Unfortunately, on pages with windows-1251 encoding, the js script encoding is not displayed correctly. Although I'm trying to explicitly specify the required encoding: hcc.charset = "windows-1251". Making two versions of js in different encodings is a bad option. Translate all sites to utf-8 - not real.

  • all real, would be hands :) Make a script that recompiles the necessary files from one encoding to another, and run on the right machines ???? profit. Longer wake up with such nonsense, it's easier to do everything right then than to crutch - Vasily Barbashev
  • I consider it your decision to be a crutch. For there is a regular solution to this problem. w3schools.com/tags/att_script_charset.asp It is only necessary to use it correctly in this case. The question is how? - Pavel Gribov
  • Do the right thing is a crutch? Well then good luck. Your life is your problem. It is better to solve it right away than to complicate everything with tags. And more and more to get rid of these problems - Vasily Barbashev
  • I strongly doubt that doing additional scripts is more appropriate than using 1 tag - Pavel Gribov
  • Additional? what are you talking about? You will change the encoding of one script, and that’s it, there will be no other. In general, this is your business. And if you don’t do it right, you can later shoot yourself in the foot - Vasily Barbashev

1 answer 1

Sometimes it is necessary to run a script in utf-8 on a page in win-1251, this is done like this: <script src="http://www.abc.ru/js/xyz.js" charset="utf-8" type="text/javascript"></script> `

  • It is required to modify the code that is in the problem - Pavel Gribov