How do i print part of a page in javascript?
I'm trying to print a specific part of my application. Show The application has a list of users, displaying their first and last name. When I click a user I get a popup with more detailed information about them. How would I go about printing just the popup for a user I clicked? The popup looks like this:
The print button isn't working yet though. asked Oct 21, 2012 at 10:44
Gregor MenihGregor Menih 4,76514 gold badges44 silver badges64 bronze badges 1 You can use simple JavaScript to print a specific div from a page.
Mystical 2,1952 gold badges21 silver badges35 bronze badges answered Oct 21, 2012 at 10:58
7 You would have to open a new window(or navigate to a new page) containing just the information you wish the user to be able to print Javscript:
HTML:
A few notes here: the anchor must NOT have whitespace between it and the div containing the content to print answered Oct 21, 2012 at 10:56
SRejectSReject 3,5661 gold badge22 silver badges40 bronze badges 2 I made this jQuery extension to print the HTML of the element selected:
See it in action here.
fresskoma 25.1k10 gold badges85 silver badges126 bronze badges answered Oct 13, 2016 at 14:03
3 Instead of all the complicated JavaScript, you can actually achieve this with simple Remember to define the
answered Mar 30, 2017 at 6:48
Cedric IpkissCedric Ipkiss 4,9762 gold badges39 silver badges60 bronze badges 1 Just use CSS to hide the content you do not want printed. When the user selects print - the page will look to the " media="print" CSS for instructions about the layout of the page. The media="print" CSS has instructions to hide the content that we do not want printed.
answered Jan 11, 2018 at 21:09 1 Here is my enhanced version that when we want to load css files or there are image references in the part to print. In these cases, we have to wait until the css files or the images are fully loaded before calling the print() function. Therefor, we'd better to move the print() and close() function calls into the html. Following is the code example:
answered Jul 4, 2017 at 3:29
hailonghailong 1,20114 silver badges18 bronze badges Styles
Jquery
Print Button Html
answered Dec 10, 2019 at 10:21
Try this:
Try it out in JSFiddle (iframes don't appear to work in StackOverflow's preview) You can see the code here, but it won't work due to what are probably security limitations in StackOverflow's renderer.
answered Aug 21, 2020 at 14:11
You can use this JQuery plugin answered Sep 19, 2021 at 13:40
aphoeaphoe 2,36625 silver badges29 bronze badges 1 I Got a better option, First separate the printable and nonprintable section by class name or id
That's all answered Jun 9, 2018 at 16:44
ArulArul 8169 silver badges21 bronze badges 1 try this one.
|