PrintCommandObject.ExecWB is not a function [Resolved]

Posted by Kasani007 under jQuery on 11/16/2016 | Points: 10 | Views : 546 | Status : [Member] | Replies : 1
I Want to print to default printer without showing dialogbox of window.print()..so that i had searched on google and i got a code as below:

if (navigator.appName == "Netscape") {
//"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);
PrintCommandObject.ExecWB(6, -1);
PrintCommandObject.outerHTML = "";
}
else {
window.print();
}

but it showing error that .. " PrintCommandObject.ExecWB is not a function "..

How can i resolve it...please help me.




Responses

Posted by: Rajnilari2015 on: 11/16/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Try this

<!DOCTYPE html>
<!-- saved from url=(0014)about:internet -->
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<script type="text/javascript">
var PrintCommandObject = null;

function printPage(){
if(PrintCommandObject)
{
try{
PrintCommandObject.ExecWB(6, 2);
PrintCommandObject.outerHTML = "";
}
catch(e){
alert(e);
window.print();
}
}
else{
window.print();
}
}
</script>
<title>PrintPage</title>
</head>

<body>
<object id="PrintCommandObject" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" width="0" height="0"></object>
<button type="button" onclick="printPage()">Print</button>
</body>

</html>


Some references may be helpful

a)https://msdn.microsoft.com/en-us/library/aa752117(v=vs.85).aspx
b)http://www.codeproject.com/Questions/784656/Printing-in-one-click-I-dont-want-print-setup-dial

--
Thanks & Regards,
RNA Team

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response