Click here to Skip to main content
15,886,077 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am not a coder, so I'm using examples that I find online. Perhaps the code below is incomplete or implemented incorrectly due to my lack of knowledge.

The use of code to display a print button but not print it does not work. I have tried three methods but none work to prevent printing a blank first page.

My page is behind a log in screen so I can't provide a link here without compromising site security. Below is the code I'm using for displaying the print button and the input code to print the page. Maybe someone can see if my code has errors or is missing something.

This code is in the head of the page.

PHP
<script type="text/javascript">
    function printpage() {
        //Get the print button and put it into a variable
        var printButton = document.getElementById("printpagebutton");
        //Set the print button visibility to 'hidden' 
        printButton.style.visibility = 'hidden';
        //Print the page content
        window.print()
        //Set the print button to 'visible' again 
        //[Delete this line if you want it to stay hidden after printing]
        printButton.style.visibility = 'visible';
    }
</script>


and this is the Input code for the button in the body of the page.

HTML
<input id="printpagebutton" type="button" value="Print this page"  önclick="printpage()"/>


Page one prints a mostly blank page with the print button, page two and three are the page content that I want to print.

Thank you.
Posted
Updated 5-Nov-13 5:00am
v2

1 solution

Hi Raymond,

The window.Print will print only the visible area on the screen and if you are getting some Blank page, then it may be available in the page.

If you delete come unwanted
, and
Tag and try the same.

Just check this:

on your Web page, use keyboard Print option [Ctrl+P], this will also print all content on the page, so see is that shows 3 pages or 2 pages.

If that shows 2 pages, then we have do find some solution.

If that shows 3 pages in normal Print, then its purely UI, just change the contents of page and remove unwanted
, and
Tag , That should work

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900