How to perform a function only when the page is printed?

2

Hi, I have a function to fix the chrome BUG when placing a table to print.

NOTE: for those who do not know this bug is that the table thead is not replicated in the following different pages of other browsers

Well, I get the scrip to fix the bug, but I already have a function in Jquery to create filters and sort my table. if I leave all the scripts on the same screen have one of them that does not work by pq would I leave the scrip to fix the chrome bug do you understand?

I would like to know if in Jquery I can create a function to call another one only when it is printing .. type a window.print (function () {     

asked by anonymous 15.01.2015 / 13:43

1 answer

1

Well, it looks like you can do this through matchMedia .

var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
    if (mql.matches) {
        // Meu script antes da impressão
    } else {
      // Depois da impressão
    }
})
    
15.01.2015 / 16:23