如果是Word,Excel的话可以换别的方法:
function PrintFile()
{
var strResult=window.confirm("确认用Word打印吗?");
if(strResult)
{
App.focus();
document.execCommand("SelectAll");
document.execCommand("Copy");
App.focus();
var WordApp=new ActiveXObject("Word.Application");
WordApp.Application.Visible=true;
var Doc=WordApp.Documents.Add();
Doc.Activate();
Doc.Content.Paste();
Doc.PrintPreview();
WordApp.DisplayAlerts=false;
Doc.Close();
WordApp.DisplayAlerts=true;
WordApp.Quit();
}
else
{
var hwnd=window.open("");
hwnd.document.write(App.innerHTML);
}
return false;
}
<div align=left id=App style="background-color:#F7F7F7;height:380px;overflow:auto;width:100%;z-index:2" contentEditable></div>