Reputation: 655
I was trying to find a solution by using this search and google, but I couldn't find anything and I hope you can help me.
I'm using the printThis plugin for print only parts of my page (in my case a DIV=modal dialog). Plugin-Page: https://github.com/jasonday/printThis
After the print-dialog is called and I printed the document I want to close my modal dialog automatically, but therefore I need a callback function.
So that's the code which is working for printing:
$(".printable").printThis({
debug: false,
printContainer: false,
pageTitle: $("#info-modal .short-info .panel-headline-wrapper h1").html(),
formValues: true,
printDelay: 0
})
Now I thought I add a "done()" function from jquery which "catches" the callback... I tried the following, but it didn't work:
$(".printable").printThis({
debug: false,
printContainer: false,
pageTitle: $("#info-modal .short-info .panel-headline-wrapper h1").html(),
formValues: true,
printDelay: 0
}).done(function(n){
//close modal dialog
});
I found something in the pull requests: https://github.com/jasonday/printThis/pull/28 But I don't know how I can use it.
I'm using the latest version of printThis (v 1.4) and jquery (v 1.11.0)
thank you very much.
cheers, Marco
Upvotes: 0
Views: 3062
Reputation: 7682
I am the author of the printThis plugin.
Due to the nature of the print dialog, your current setup won't work, because there is no event tied to the print dialog (when it's fired, done, etc.). Additionally, $.done
is part of a deferred object, or promise. It won't work in this context.
I haven't yet tested the pull request, but it 'might' work because the browser probably halts and stacks javascript execution while the print dialog is open. However, I don't know how this works across browsers.
If you look in the pull request, the submitter added instructions in the header with the other instructions. You essentially put a function in the config object.
There is another option. You can simply close the modal on the same click event you are using to trigger the print functionality. This approach would be simpler, until I figure out a way to effectively incorporate callbacks.
Upvotes: 2