0

I have a javascript print feature that uses jqprint (though I've made some minor adjustments to the code).

This print feature works on IE8 and Chrome without a problem. On IE9 though, it shows no JS errors and the browser print dialogue shows up as expected, but once I click print, nothing happens. Eventually all applications on my computer start lagging and I have to reboot though.

If I open the developer tool kit (F12) and set the document mode to IE8 standards, it prints fine in IE9.

What's going on? I'm honestly baffled...

Edit:

My computer is not hooked up to a printer so I am using the built in "Microsoft XPS Document Writer" for testing. I have tested the code on an actual printer in IE8 and Chrome though, and it does work.

Update:

This stopped working today for some reason, anyone have any ideas?

Lifes
  • 1,226
  • 2
  • 25
  • 45
  • do you have `console.log` somewhere? if so, just enclose it with `if(console.log){...}` – karthikr Apr 15 '13 at 18:30
  • 1
    What happens if you open the console and leave it on IE9 standards and click print? – Kevin B Apr 15 '13 at 18:33
  • @KevinB I figure you're guessing Lindsay may have fallen foul of this issue: http://stackoverflow.com/questions/7742781/why-javascript-only-works-after-opening-developer-tools-in-ie-once and I agree that it's a good guess. :) – Mark Amery Apr 15 '13 at 18:35
  • I searched the jqprint code and it doesn't have console, but that's a good thing to know for future projects. Also, just opening the IE developer tool kit doesn't solve the problem. – Lifes Apr 15 '13 at 18:46
  • @KevinB the print dialogue shows up, I click Print, then nothing. No errors. Eventually, all my other applications slow down and I have to reboot. – Lifes Apr 15 '13 at 18:47
  • can you see if there is something allready in your printerpipe? the stack where files are placed right before they got send to the printer – Ol Sen Apr 15 '13 at 19:01
  • @codelio how do I check that? IE9 is definitely doing something since after I try to print, my CPU usage goes through the roof. – Lifes Apr 15 '13 at 19:03
  • if possible and assuming you could have pdf creator tool you could try to have look inside the printdata, just to figure out if IE9 has trouble with sending the content out – Ol Sen Apr 15 '13 at 19:03
  • so if the CPU is running and your webpage is running fine, means the (hang) is then not in IE9, mostly if CPU goes up to the roof its something with kernel functions which goes wrong. i'm working on a mac, we dont know such things :) just a joke! but printerfiles are somewhere in c:/windows/printer/ or not? damn i cant help out – Ol Sen Apr 15 '13 at 19:07
  • Thanks for trying codelio, once I realized other sites were printing on IE9, I knew it had to be a JS problem. – Lifes Apr 15 '13 at 20:54

1 Answers1

0

I have no idea why, but I got it to work.

When it was calling the print function, it was calling it on a jquery object it had just created (the iframe). I changed the jqprint code so it re-grabs the object every time.

Original jqprint code:

 $iframe[0].contentWindow.document.close();
 ....

Modified jqprint code:

$('iframe')[0].contentWindow.document.close();
$('iframe')[0].contentWindow.focus();
$('iframe')[0].contentWindow.print();
$('iframe')[0].contentWindow.close();
Lifes
  • 1,226
  • 2
  • 25
  • 45