son*_*phi 4 javascript unicode internet-explorer activex internationalization
我使用以下函数将文本保存到文件(在IE-8 w/ActiveX上).
function saveFile(strFullPath, strContent)
{
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
var flOutput = fso.CreateTextFile( strFullPath, true ); //true for overwrite
flOutput.Write( strContent );
flOutput.Close();
}
Run Code Online (Sandbox Code Playgroud)
如果文本完全是Latin-9,但是当文本甚至包含单个UTF-8编码字符时,代码工作正常,则写入失败.
似乎ActiveX FileSystemObject不支持UTF-8.我首先尝试使用UTF-16编码文本,但结果是乱码.什么是变通方法?
试试这个:
function saveFile(strFullPath, strContent) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var utf8Enc = new ActiveXObject("Utf8Lib.Utf8Enc");
var flOutput = fso.CreateTextFile(strFullPath, true); //true for overwrite
flOutput.BinaryWrite(utf8Enc.UnicodeToUtf8(strContent));
flOutput.Close();
}
Run Code Online (Sandbox Code Playgroud)