I need to limit the number of impressions of an HTML document .
Currently if the file is generated (via PHP), register in the bank a sts_impresso = 1
flag, however, there are times when the user did not print for some situations:
- You clicked the cancel button;
- Closed the window;
- There were problems with internet connectivity at the time of downloading the file to be printed.
And in the three situations above, it was already marked as printed and the document can not be printed again.
Then I thought about performing the control via JavaScript:
function imprimir() {
url = URL_DO_DOCUMENTO_IMPRESSO; // url do documento
var nw = window.open(url, "popView" , 100, 100, "yes", "yes", true); // abro em nova janela
$(nw).ready(function () { // assim que carregou, chama o print
nw.print();
});
}
How to detect whether the user clicked the Print button or the Cancel button on the browser print screen, or did he simply close the window?
From confirmation of printing, I want to make an AJAX request to mark it as printed and then close the window.
This is just an implementation idea to solve the problem described in the title of this question.
Different feasible implementations for solving the problem are welcome.
Note: I know that everything in the browser can be mocked and I can not trust the code coming from the Browser, but I need to at least minimize this problem.