php - Prevent print dialog from refreshing page - Stack Overflow

I have an invoice which I have set up a print button for:<script><!--Function for printing i

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
Add a ment  | 

2 Answers 2

Reset to default 6

I 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

相关推荐

  • php - Prevent print dialog from refreshing page - Stack Overflow

    I have an invoice which I have set up a print button for:<script><!--Function for printing i

    2天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信