I am doing something like this in javascript to print a section of my page on click of a link
function printDiv() {
var divToPrint = document.getElementById('printArea');
var newWin = window.open();
newWin.document.write(divToPrint.innerHTML);
newWin.print();
newWin.close();
}
It works great in Firefox but not in IE.
Could someone please help
Close the window only when it is not IE:
Add these lines after
newWin.document.write(divToPrint.innerHTML)
Then print function will work in all browser...
The way we typically handle printing is to just open the new window with everything in it that needs to be sent to the printer. Then we have the user actually click on their browsers Print button.
This has always been acceptable in the past, and it sidesteps the security restrictions that Chilln is talking about.
For Firefox use
for IE use
see also Unable to print an iframe on IE using JavaScript, prints parent page instead