Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set charset="utf-8" in the javascript file itself

I am trying to set charset="utf-8" inside the javascript file itself, not in the script tag, I know that I can do this:

<script type="text/javascript" charset="UTF-8" src="xyz.js"></script>

But unfortunately, this solution needs me to do the same step with hundreds of websites which are using the same script. so I am trying to set the charset in the javascript file itself. Is this possible?

thanks

like image 709
Jehad Nasser Avatar asked Jun 17 '17 15:06

Jehad Nasser


People also ask

How do I change my UTF-8 character set?

Click Tools, then select Web options. Go to the Encoding tab. In the dropdown for Save this document as: choose Unicode (UTF-8). Click Ok.

What is charset property in JavaScript?

The charset attribute specifies the character encoding used in an external script file. The charset attribute is used when the character encoding in an external script file differs from the encoding in the HTML document.

What is UTF-8 in JavaScript?

UTF-8 can represent any character in the Unicode standard. UTF-8 is backwards compatible with ASCII. UTF-8 is the preferred encoding for e-mail and web pages. UTF-16. 16-bit Unicode Transformation Format is a variable-length character encoding for Unicode, capable of encoding the entire Unicode repertoire.


1 Answers

I found another way, so instead of declaring charset="UTF-8" for the script tag like this:

<script type="text/javascript" charset="UTF-8" src="xyz.js"></script>

I can declare the charset for the web page itself using meta tag, so I can append <meta charset="UTF-8"> to the DOM dynamically, and end up with something like:

<head>
...
  <meta charset="UTF-8">
...
</head>
like image 194
Jehad Nasser Avatar answered Sep 18 '22 17:09

Jehad Nasser