0

I would like to print a whole page when a button is clicked. I am using window.print() but its not working for ie. I googled for a solution but nothing hellped. Maybe someone know what I am doing wrong.

MyCode:

$('#PrintTool').click(function () {
var printVal = document.documentElement.innerHTML;
var newWin = window.open();
newWin.document.write(printVal);
newWin.document.close();
newWin.focus();
newWin.print();
newWin.close();
});

I hope you can help me

user3490546
  • 292
  • 6
  • 16

1 Answers1

1

checkout: window.print() not working in IE

Working sample: http://jsfiddle.net/Q5Xc9/1/

<html>
<head>
<script type="text/javascript">
  function openWin()
  {
    var myWindow=window.open('','','width=200,height=100');
    myWindow.document.write("<p>This is 'myWindow'</p>");

    myWindow.document.close();
    myWindow.focus();
    myWindow.print();
    myWindow.close();

  }
</script>
</head>
<body>

<input type="button" value="Open window" onclick="openWin()" />

</body>
</html>
Community
  • 1
  • 1
Smudoo
  • 562
  • 3
  • 11
  • it doesn't work...just opens a new window what it also did previously. When i use a different computer or virtual maschine, it works fine. But on several development maschines it doesnt work. In chrome or firefox all works fine. – user3490546 Aug 11 '15 at 07:35
  • 1
    just try this in the following order: myWindow.document.close(); myWindow.focus(); myWindow.window.print(); instead of your last three steps. – Smudoo Aug 11 '15 at 07:39