I have an invoice which I have set up a print button for:
</script>
<!--Function for printing invoice-->
<script>
function printpage()
{
window.print()
}
</script>
<button id="print" name="print" class="btn btn-info"onClick="printpage()">Print Invoice</button>
Now on clicking the button, the print dialog appears as expected, however, if I cancel the print option, the invoice page refreshes and all the information is lost.Is there a way that I can cancel the print dialog but not have the page refreshed?
I suspect I need to reference the click event of the dialog box, but this is where I run into difficulty. Thank's
Just for anyone looking in the future, the button HTML was amended to:
<button id="print" name="print" type="button"class="btn btn-info"onClick="printpage()">Print Invoice</button>
This stops the print dialog box when canceled, from refreshing the page and thus from losing any info that was dynamically produced/pulled in from a DB.
I have an invoice which I have set up a print button for:
</script>
<!--Function for printing invoice-->
<script>
function printpage()
{
window.print()
}
</script>
<button id="print" name="print" class="btn btn-info"onClick="printpage()">Print Invoice</button>
Now on clicking the button, the print dialog appears as expected, however, if I cancel the print option, the invoice page refreshes and all the information is lost.Is there a way that I can cancel the print dialog but not have the page refreshed?
I suspect I need to reference the click event of the dialog box, but this is where I run into difficulty. Thank's
Just for anyone looking in the future, the button HTML was amended to:
<button id="print" name="print" type="button"class="btn btn-info"onClick="printpage()">Print Invoice</button>
This stops the print dialog box when canceled, from refreshing the page and thus from losing any info that was dynamically produced/pulled in from a DB.
Share edited May 30, 2013 at 9:06 David asked May 30, 2013 at 8:39 DavidDavid 432 silver badges9 bronze badges 2- Sounds heavily browser-dependent to me. Is this Internet Explorer by any chance? Most sites open a new tab with the information formatted for printing, and I suppose since it's static content it doesn't matter if it refreshes. – Dave Commented May 30, 2013 at 8:43
- Cheers Dave, I should have mentioned that the content is read in from a DB, as too are the header and footer content.@Quentin solved the issue. Again, thank's. Dave – David Commented May 30, 2013 at 9:03
2 Answers
Reset to default 6I tried reproducing your problem, but the only way I could do so was to put the button in a form.
Say type="button"
to stop it being a submit button that submits the form.
Try to return false from the onclick handler:
onClick="printpage(); return false"
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744913105a4600671.html
评论列表(0条)