js window.open 弹出窗口设置 UTF-8编码的问题解决
发现弹出空白窗口时,页面为unicode编码,查询了下,发现document.write默认使用unicode编码。后来可以用pwin.document.charset=”UTF-8″;语句来解决编码问题。
function log() {
var newwindow=window.open('about:blank');
var printerCode = $("#printerCode").val();
var logUrl= getRootPath().replace("HsCloudPrint","") + "HsFiles/logFiles/"+printerCode+".log";
htmlobj=$.ajax({url:logUrl,type:"get", contentType: "application/x-www-form-urlencoded; charset=utf-8", async:false});
if(htmlobj.status=="200"){
newwindow.document.write(htmlobj.responseText);
newwindow.document.charset="UTF-8";
}else{
newwindow.close();
}
}
var printerCode = $("#printerCode").val();
var logUrl= getRootPath().replace("HsCloudPrint","") + "HsFiles/logFiles/"+printerCode+".log";
htmlobj=$.ajax({url:logUrl,type:"get", contentType: "application/x-www-form-urlencoded; charset=utf-8", async:false});
if(htmlobj.status=="200"){
newwindow.document.write(htmlobj.responseText);
newwindow.document.charset="UTF-8";
}else{
newwindow.close();
}
}