How do I print out a particular div in my page using Javascript?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
I would suggest using a 'print' css stylesheet, in which you can specify to hide the dom elements you do not want to print (with display: none). Try to only make the div you want to print visible in the print stylesheet.
Another option would be to use a popup window that displays when clicked on the 'print' button in the page. In the popup window only display the div contents, and trigger a print dialog on document load.
Javascript doesn't print. You have to insert the div somewhere into the DOM (Document Object Model).
I suggest learning some jQuery and using the
.append()
,.prepend()
or.html()
functions.Here is an implementation that has been tested in IE8 and FF3.6.6 on windows There are some stuff that can be streamlined, but other that are necessary (display:none on the iframe will print nothing)