script.charset="GBK";//or other charset
How to define the chatset of a certain dom appended to any webpage with different chatset by jquery(or js)
-
18-10-2022 - |
Question
I am doing a chrome extension which may append a button to any web pages using chrome extension
, contentscript
. The problem is the charset of the web pages are uncertain, which means that I may append my node to the web pages with different charset. Sometimes it may come with messy code.
Here's the example:
content_script.js:
(function(){
var script = document.createElement('script')
script.setAttribute('src', 'url_to_my_javascript')
document.body.appendChild(script)
})()
my_javascript.js:
$('body').append('<button>确定(chinese,means ok)</button>')
That comes with messy code on some pages with 'gbk' charset
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow