如何设置charset ="utf-8"?在javascript文件本身中 [英] How to set charset="utf-8" in the javascript file itself

查看:781
本文介绍了如何设置charset ="utf-8"?在javascript文件本身中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在javascript文件本身而不是script标记中设置charset ="utf-8", 我知道我可以做到:

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>

但是不幸的是,此解决方案需要我对使用相同脚本的数百个网站执行相同的步骤.因此,我试图在javascript文件本身中设置字符集. 这可能吗?

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?

谢谢

推荐答案

我找到了另一种方法,所以不必像这样为脚本标记声明charset="UTF-8":

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>

我可以使用meta标记声明网页本身的字符集,因此可以动态地将<meta charset="UTF-8">附加到DOM,最后得到类似以下内容:

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>

这篇关于如何设置charset ="utf-8"?在javascript文件本身中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆