Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't prevent the user from printing, but you can hide everything when the user prints the document by using simple CSS:</p> <pre><code>&lt;style type="text/css" media="print"&gt; * { display: none; } &lt;/style&gt; </code></pre> <p><a href="http://jsfiddle.net/qaapD/11/" rel="nofollow noreferrer">Updated fiddle</a>.</p> <p>If you would like to show the visitor a custom message when he/she try to print rather then just a blank page, it's possible with client side code but first wrap all your existing contents like this:</p> <pre><code>&lt;div id="AllContent"&gt; &lt;!-- all content here --&gt; &lt;/div&gt; </code></pre> <p>And add such a container with the custom message:</p> <pre><code>&lt;div class="PrintMessage"&gt;You are not authorized to print this document&lt;/div&gt; </code></pre> <p>Now get rid of the <code>&lt;style type="text/css" media="print"&gt;</code> block and the code would be:</p> <pre><code>if ('matchMedia' in window) { // Chrome, Firefox, and IE 10 support mediaMatch listeners window.matchMedia('print').addListener(function(media) { if (media.matches) { beforePrint(); } else { // Fires immediately, so wait for the first mouse movement $(document).one('mouseover', afterPrint); } }); } else { // IE and Firefox fire before/after events $(window).on('beforeprint', beforePrint); $(window).on('afterprint', afterPrint); } function beforePrint() { $("#AllContent").hide(); $(".PrintMessage").show(); } function afterPrint() { $(".PrintMessage").hide(); $("#AllContent").show(); } </code></pre> <p>Code is adopted from <a href="https://stackoverflow.com/a/15662720/447356">this excellent answer</a>.</p> <p><a href="http://jsfiddle.net/qaapD/13/" rel="nofollow noreferrer">Updated fiddle</a>. (showing message when printing)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload