Window.open () opens the txt file with garbled Chinese characters.

opening the txt file with the following code in the js code will cause Chinese garbled. Is there any solution?

let newWin = window.open("_blank");
newWin.location = "a.txt";
//newWin.document.charset="UTF-8";
console.log("88888:",newWin.document.charset)
newWin.document.characterSet="UTF-8";

uses several attribute assignments such as charset, but attributes such as charset are read-only, so this approach has no effect.

Mar.12,2021

var newUrl= "data:text/html;charset=utf-8," + encodeURI (url). Replace (/-sharp/g, "% 23");
window.open (newUrl);


set header ('Content-Type: text/plain; charset=utf-8') on the backend.
or don't open it on a new page, just insert the contents of the txt file in the current page with the

 or  tag. 


Brother, how did you solve it?

Menu