showing results for - "override print command javascript"
Andrés
22 Nov 2020
1function beforePrint() {
2    console.log('Do something special before print');
3}
4
5function afterPrint() {
6    console.log('Do something after print');
7}
8
9if (window.matchMedia) {
10    window.matchMedia('print').addListener(function (mql) {
11        if (mql.matches) {
12            beforePrint();
13        }
14        else {
15            afterPrint();
16        }
17    });
18}
19// For IE, does not attach in browsers that do not support these events
20window.addEventListener('beforeprint', beforePrint, false);
21window.addEventListener('afterprint', afterPrint, false);
22