cchitsiang
11/7/2013 - 5:01 AM

JavaScript Print: Bypass Printer Dialog in IE and Firefox

JavaScript Print: Bypass Printer Dialog in IE and Firefox

var OLECMDID = 6;
/* OLECMDID values:        * 6 - print        * 7 - print preview        * 1 - open window        * 4 - Save As        */
if (navigator.appName == "Microsoft Internet Explorer")
{
     var PrintCommand = '<object ID="PrintCommandObject" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
     document.body.insertAdjacentHTML('beforeEnd', PrintCommand);
     if(PrintCommandObject)
     {
       try
       {
        PrintCommandObject.ExecWB(OLECMDID, -1);
        PrintCommandObject.outerHTML = "";
       }
       catch(e){
         window.print();
         }
     }
}
else {
    window.print();
}

//http://justtalkaboutweb.com/2008/05/09/javascript-print-bypass-printer-dialog-in-ie-and-firefox/