How to set print options via javascript?

Asked

Viewed 2,037 times

5

Is it possible? I would like for example to remove the default margin and remove header and footer. Already open the print window with these settings.

  • I think a complete answer would be Erlon’s, but with the addition of Beet, as it may be a valid alternative for some cases. If there is an answer like this mark as the correct and delete this comment. I think this way can help more future visitors.

  • 1

    This Q&A has a deleted answer pointing to this: https://code.google.com/p/jzebra/

2 answers

6


It is possible using CSS, via media type print

Suppose you want to hide the tag header when prompted to print:

<header>
   <h1> Preciso sumir na impressão</h1>
<header>
<p> Eu quero aparecer na impressão </p>

In your CSS, you must define:

@media print {
  header {
    display: none
  }
}
  • This already helps quite +1

4

These settings are from the browser and not from the page.
A while ago I researched a lot about the subject too and ended up solving the problem by setting these print settings as browser settings in the document of system prerequisites.

So unless it is possible with Javascript to manipulate browser settings that nay it is possible to be done.

  • Yes, a while ago I came across the same question and then settled for the impossibility. +1

Browser other questions tagged

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