How do you print html content on click of a button but not the page?
I want to print some HTML content, when the user clicks on a button. Once the user clicks on that button, the print dialog of the browser will open, but it will not print the webpage. Instead, it will print the some other HTML content which is not displayed on the page. Show While asking this question, there are few
solutions coming into my mind. But I am not sure whether those are good ideas or something better can be done. One of those solutions are: I can keep this HTML content in a div and make it Any better idea? asked Jun 3, 2013 at 10:28
3
I came across another elegant solution for this: Place your printable part inside a div with an id like this:
Now let's create a really simple javascript:
SOURCE : SO Answer
answered Jun 3, 2013 at 11:05
asprinasprin 9,47111 gold badges67 silver badges112 bronze badges 11 Here is a pure css version
Jonathan 2,3254 gold badges22 silver badges37 bronze badges answered Jun 3, 2013 at 10:36
2ne2ne 5,5489 gold badges29 silver badges49 bronze badges 3
According to this SO link you can print a specific div with
answered Jun 3, 2013 at 10:35
JaayJaay 2,0731 gold badge15 silver badges33 bronze badges 6 I Want See This Example http://jsfiddle.net/35vAN/
answered Jul 25, 2014 at 12:27
1 Below Code May Be Help You :
answered Jun 3, 2013 at 10:36
Butani VijayButani Vijay 4,0902 gold badges28 silver badges60 bronze badges 1 If you add and remove the innerHTML, all javascript, css and more will be loaded twice, and the events will fire twice (happened to me), is better hide content, using jQuery and css like this:
The div "site-container" contain all site, so you can call the function like:
answered Jul 4, 2014 at 0:26
Alejo JMAlejo JM 8917 silver badges12 bronze badges 1 How do I print a certain part of a web page in HTML?You can use this function for print a specific area of web page or full web page content. Use printPageArea() function on onclick event of print button element and provide the content area div ID which you want to print.
How do I print only certain parts of a website?Only Print Text You Highlight on a Page
Highlight the text and/or images you want to print on a web page. Now in your browser go to File > Print or simply use the Ctrl + P keyboard combination. The Print screen comes up. Select the Printer you want to use.
How do I hide an element when printing a web page?To hide the element, add “display:none” to the element with CSS.
How do I print a button click page?You can easily add a print button to your web page by adding the following code to your HTML document where you want the button to appear:. onclick="window.print();return false;" />. print.. type="text/css" media="print" />. body {visibility:hidden;} .print {visibility:visible;}. |