jasonday / printThis

jQuery printing plugin; print specific elements on a page

Home Page:https://jasonday.github.io/printThis/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disable page reload after printing?

hcgreier opened this issue · comments

Hi, thank you for this nice git!

I built a page just for private use which one sets up a chess position (chessboard.js), give annotations and so forth...
I can print it without problems to a PDF file with your code, CSS works fine.

The only thing I want is that the page should not reload after the printing process, because then the setting are gone.
So is there a method to prevent the page from reloading?
I wrote a cookie function which stores my settings and gave it to the beforePrint option, and recall it after printing, but this does not work.

Thank you so much,
greetings,
hc

Hi @hcgreier,
so the way this plugin works is that it creates an iframe on the page, copies over the content you specify, and prints that iframe, and then removes the iframe.

It doesn't do PDF generation, so I assume you meant that you print to PDF in the print dialog. As for the reload, it shouldn't be reloading the parent page (as there's nothing that triggers that in the code) and I haven't received any reports of that happening.

Can you please post any relevant code, such as the printThis declaration?

Hi Jason,

thank you for your response!
Yes, the print dialog pops up and I use Adobe PDF as printer option.
The code is as follows:

$("#printBtn").click(function () {
    let printout = $('#thePrint');
    printout.printThis(
      {
        loadCSS: "http://127.0.0.1:5500/css/print.css",
        printContainer: true,
        printDelay: 500,
        removeInline: false,
        afterPrint: null
      }
    );
  });

All to be printed is inside div with id "thePrint". And as I said, it works fine. But after the printing is finished, the page reloads and my settings are gone. I guess I'm just sitting too long on my PC - I can't see the forest for the trees ;)

EDIT:
I tested Browsers FF, Chrome, Edge on WIN10 machine. No matter if I "Print as PDF" or "Save as PDF" in the printer dialog, the page always gets reloaded.

Thank you,
hc

Have you tried this in a production environment versus a local development server?

Hi Jason,

thank you for your answer.
I put the print content into a modal popup, from where I then print the middle DIV. This works fine. The modal keeps open and there is no page reload. But maybe this issue was due to the local server and it works if you load it up to the actual website.

Thank you,
hc

Glad it's working.