i.e. When I click the button from my page, the desired page content should get printed in a sheet. The main goal over here is, it should not show me with the print dialog box/print preview of the page asking for OK or CANCEL button where we can also choose for multiple prints of a particular page. Thanks in advance.
Asked
Active
Viewed 1,439 times
0
-
2DUPLICATE [http://stackoverflow.com/questions/15105674/how-can-i-prevent-the-user-from-printing-multiple-copies-of-a-html-page][1] [1]: http://stackoverflow.com/questions/15105674/how-can-i-prevent-the-user-from-printing-multiple-copies-of-a-html-page – simply-put Feb 27 '13 at 07:08
-
Did you try my solution? – Ravinder Singh Feb 27 '13 at 08:30
2 Answers
0
What is the browser you are targeting? There are some browser specific ways of doing this.
For IE :
<script language='VBScript'>
Sub Print()
OLECMDID_PRINT = 6
OLECMDEXECOPT_DONTPROMPTUSER = 2
OLECMDEXECOPT_PROMPTUSER = 1
call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
End Sub
document.write "<object ID='WB' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>
</script>
window.print();
Ref : msdn blog

Don Srinath
- 1,565
- 1
- 21
- 32
-
-
-
@Ravinder Singh , yah I meant to add a comment, my mistake. Anyway now I made it an answer. Thanks for pointing it out. – Don Srinath Feb 27 '13 at 07:47
0
Create a print.js file by this code :
// ----------------------------------------------------------------------- (function($) { var opt; $.fn.jqprint = function (options) { opt = $.extend({}, $.fn.jqprint.defaults, options); var $element = (this instanceof jQuery) ? this : $(this); if (opt.operaSupport && $.browser.opera) { var tab = window.open("","jqPrint-preview"); tab.document.open(); var doc = tab.document; } else { var $iframe = $(""); if (!opt.debug) { $iframe.css({ position: "absolute", width: "0px", height: "0px", left: "-600px", top: "-600px" }); } $iframe.appendTo("body"); var doc = $iframe[0].contentWindow.document; } if (opt.importCSS) { if ($("link[media=print]").length > 0) { $("link[media=print]").each( function() { doc.write(""); }); } else { $("link").each( function() { doc.write(""); }); } } if (opt.printContainer) { doc.write($element.outer()); } else { $element.each( function() { doc.write($(this).html()); }); } doc.close(); (opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).focus(); setTimeout( function() { (opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).print(); if (tab) { tab.close(); } }, 1000); } $.fn.jqprint.defaults = { debug: false, importCSS: true, printContainer: true, operaSupport: true }; // Thanks to 9__, found at http://users.livejournal.com/9__/380664.html jQuery.fn.outer = function() { return $($('').html(this.clone())).html(); } })(jQuery);
And then include your print.js on an html page and see the demo of this :
<script> jQuery(document).ready(function () { jQuery("#printBtn").click(function(){ jQuery("#print").jqprint(); }); }); </script> <input type="button" id="printBtn" value="Print" /> <div id="print"> This will print this content. </div>

Ravinder Singh
- 3,113
- 6
- 30
- 46
-
I tried implementing it, but it didn't work out. When I click on the button there is no action. – Ajay Kumar R Feb 28 '13 at 13:27