0

I have tried working on the following lines:-

$(document).ready(function () {
  $('input').attr('readonly', true);
  window.open("", "_self");
  window.print();
  window.close();
});

The above code enables to open the print dialog but prompts the user to click Print.

I have researched quite a bit on it and the nearest i got was a vb script which achieves the same.

Can someone point me in the right direction? Thanks in advance.

Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
karthi
  • 41
  • 9
  • 1
    That VB script solution works only in IE http://stackoverflow.com/questions/9213660/html-javascript-one-click-print-no-dialogs There is no way of doing this for security reasons – online Thomas Dec 08 '15 at 09:45
  • But i suppose its definitely achievable using some tweaks and hacks. There is nothing in the web system that cannot be automated :P – karthi Dec 08 '15 at 09:53
  • Haha that's where you are wrong: Javascript runs very sandboxed and you can't bypass any security checks like these. Browsers are supposed to be safe you know – online Thomas Dec 08 '15 at 10:01
  • True that.. but consider a scenario where you have loads of documents like bank transcripts that need the print to be automated as and when the code encounters a print? – karthi Dec 08 '15 at 10:05
  • Then use for example C#'s `WebBrowser Class` basically building your own minibrowser (It sounds like a lot of work, but it isn't using this class). Javascript just isn't fit for what you try to do. – online Thomas Dec 08 '15 at 10:19
  • That does sound like stretching a leg, but definitely worth a try. – karthi Dec 08 '15 at 10:24

0 Answers0