admin管理员组

文章数量:1428473

I add an external JavaScript file like this:

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <script charset="utf-8" type="text/javascript" src="js/panel.js" ></script>
</head>

But the text stored in panel.js file is displayed like this in the HTML file:

H69�*

When I put JavaScript code in the HTML page, the text is displayed properly. But when I put JavaScript code in panel.js, it does not work.

I add an external JavaScript file like this:

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <script charset="utf-8" type="text/javascript" src="js/panel.js" ></script>
</head>

But the text stored in panel.js file is displayed like this in the HTML file:

H69�*

When I put JavaScript code in the HTML page, the text is displayed properly. But when I put JavaScript code in panel.js, it does not work.

Share Improve this question edited May 27, 2017 at 22:19 Badacadabra 8,5357 gold badges31 silver badges54 bronze badges asked Feb 23, 2015 at 6:45 adib16adib16 1,7073 gold badges22 silver badges36 bronze badges 3
  • Is panel.js definitely saved as UTF-8? – Evan Knowles Commented Feb 23, 2015 at 6:46
  • i use centos and do not know how to save file as utf-8 – adib16 Commented Feb 23, 2015 at 6:48
  • lying about the encoding on the script tag won't help, you need to adjust the server or use ascii js files. – dandavis Commented Feb 23, 2015 at 7:35
Add a ment  | 

2 Answers 2

Reset to default 6

Then the file maybe is not properly saved as UTF-8.

$ file -i panel.js

What's the output?

If you use, for example Vi, open the file and save it with:

:w ++enc=utf-8 %

in the mac OS it is a capital -i...like this:

file -I

本文标签: htmlCharset UTF8 for external JavaScript fileStack Overflow