Printing from a popup window

Recently one of my buddy tried to use window.print from a popup window
he were working on in webpage. And everytime he called window.print, it
doesn’t worked and the pop window went blank. He asked me to sort this out.

I tried out with this below technique and it worked.
Actually, window.print doesn’t work in a child window which is opened using the window.open method
we have to use it as

function printChildWindow() {
var newWindow = window.open("yourhtmlhere.html", "newWindow", "height=200,width=300");
......................
newWindow.document.close();
}
The window.print command stalls because the new window is still open
for input. If it is closed with windowName. document. close ; then the print
command will work as expected.