Forum Moderators: open
So I have a problem I'd like to present.
I have a page which is generated by javascript in response to user form input. There is a link to print this page if the user wants. In an effort to avoid printing the non-essentials, I set up a function to pull out the essential content (contained in the generated code inside a <div id="printable">), write it to a new window, and call the window.print() function.
All of this works fine and dandy. I then added a window.close() (actually it's printWin.close()) in order to save the user the trouble of having to close the print window.
Running from my hard drive, this, too, works fine. The print window opens, fills with the right content, calls up the print dialog, and closes down the print window. But if I put it online, it's a whole different story. It opens the print window, then closes it before the print dialog ever opens.
Any thoughts? I'd appreciate any response I can get.
Instead of building a separate print window, you might try a CSS @media rule to print just the parts you want.
[w3.org ]
If I get this right (thank you, Bernard, for the link), @media is a way to specify CSS styles that apply only to the page as a peice of the specified media (in this case as a printed document). So when the browser goes to print the page, it will send it to the printer using the @media print styles?
If that is the case, I would need to use CSS to get rid of the un-wanted parts of the page (the nav bar, for instance).
I'm thinking of display:none or visibility:none.
Sound right?
Say 'hello' from over here.
However, since this was a JavaScript question in a JavaScript forum, I'll give you a JavaScript solution.
Delay the window.close() using the setTimeout function, like this:
setTimeout("window.close()",1000); // Hint: 1000 = 1 second, adjust this if you need to.