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
Just wait some time before closing the window!
add checking condition for onload
I am not sure but i think it occurs because of the security rules of the InternetExplorer...
If you call a function like print() it asks the user manually if he wants to permit active scripting, if he clicks on the yellow bar and selects 'Yes', the print dialog appears. If you click 'No' or just don't do anything it is not executing the parts which are considered as active scripting or other security relevant javascript functions.
In your example the window is opened then print() is called, confirmation bar pops up (nothing is selected, in fact nothing can be selected due to the short time), newWin.close() is called, window closes.
You should try adding the page to the trusted sites in InternetExplorer or change security settings.
There may be a way of handling the security policies in the javascript itself but i don't know much about InternetExplorer Security Policies.
Hope this helps
Add newWin.document.close();, like so:
This makes IE happy. HTH, -Ted
Just to add some additional information. In IE 11, using merely
causes
to be undefined. To resolve this, use
This will also work correctly in Chrome, Firefox and Safari.
I don't have enough reputation to comment, so had to create an answer.