Friday, March 22, 2013

Socket.IO 0.9.x client disconnect failed when using namespace

socket.disconnect() used to be working with my server. Then I changed my server to be using namespace, and the client side disconnect no longer works. Luckily I can find this from Google.
 socket.socket.disconnect()  

Thursday, March 21, 2013

Click a button to print an embedded PDF file without the printing dialog in Internet Explorer (silent print)

I recently helped a friend implementing a button to click, and it sends a hosted pdf to the defaulted printer without the printing dialog in IE8. I googled this about a few dozen pages and finally came across http://stackoverflow.com/questions/975652/silent-print-a-embedded-pdf. So here is the test.html. And due to the ActiveX used, you have to make this page to be trusted or in intranet.
 <html>  
 <head>  
 <title>Test</title>  
 <script>  
 function printpdf(pdf_path) {  
  // remove the previous pdf <object> if existed  
  var elem = document.getElementById("pdf");  
  if (elem) {  
   elem.parentNode.removeChild(elem);  
  }  
  document.body.insertAdjacentHTML('beforeEnd', '<object id="pdf" classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="0" height="0"><param name="src" value="' + pdf_path + '"/></object>');  
  pdf.printAll();  
  return false;  
 }  
 </script>  
 </head>  
 <body>  
 <!-- http://stackoverflow.com/questions/975652/silent-print-a-embedded-pdf -->  
 <button onclick="printpdf('sample.pdf');">Print PDF</button>  
 </body>  
 </html>  
I put it in my dropbox as well: https://dl.dropbox.com/u/48348/pdf/pdf.html (put dropbox domain into trusted sites) EDIT: Adobe Reader 8 was reported to leave a blank Adobe Reader application running whenever you click, then version 11 doesn't have this problem.