How to run a function only when printing the page?

Asked

Viewed 379 times

2

Hello, well I have a function to fix Chrome BUG when placing a table to print.

  • NOTE: for those who do not know this bug is that the table is not replicated in the following pages, different from other browsers.*

well, I get the script to fix the bug, but I would like to leave the function that fixes the bug only when printing.

Then I wonder if in Jquery I can create a function to call another only when printing.. like a window.print(Function(){

  • Douglas, welcome to [en.so]! Even if you could run a Script to change what is printed there is no meiow (and even if there would be something of extreme complexity) to calculate positions and redistribute the elements in the output to include the headers on each page.

1 answer

2


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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.