Page js encountered garbled code problems and the solution is unable to transcode the case

  • 2020-03-30 02:46:43
  • OfStack

Today, I encountered a difficult problem, in the old project to add some js files and the old project coding format is inconsistent garble code. The old page is GB2312, the linked js file is utf-8, and neither file can be converted.

The first idea is to convert the Chinese in the js file to unicode encoding. This was done at the expense of readability, and the Chinese was all coded.

In hindsight there should be a better way, then go to baidu, the method is as follows:
 
<script type='text/javascript' src='xxxuft.js' charset='utf-8'></script> 

Add the red setting, which means to specify the js file encoding format. This method is also suitable for cases where js files dynamically generated on the server side cannot be transcoded by the front-end staff, and js files of other websites loaded across domains.

Related articles: