Disabling browser print options (headers, footers, margins) from page?

后端 未结 9 810
生来不讨喜
生来不讨喜 2020-11-22 08:34

I have seen this question asked in a couple of different ways on SO and several other websites, but most of them are either too specific or out-of-date. I\'m hoping someone

9条回答
  •  伪装坚强ぢ
    2020-11-22 08:54

    Any recent version of Chrome and Opera, as well as Firefox 48 alpha 1 and greater

    You can set the page margin to a size that's too small to contain the text in order to disable this (borrowing from awe's answer):

    @page {
      size: auto;  /* auto is the initial value */
      margin: 0mm; /* this affects the margin in the printer settings */
    }
    html {
      background-color: #FFFFFF;
      margin: 0px; /* this affects the margin on the HTML before sending to printer */
    }
    body {
      border: solid 1px blue;
      margin: 10mm 15mm 10mm 15mm; /* margin you want for the content */
    }
    1. Middle-click to open in new tab
    2. Print

    For versions of Firefox up to 48 alpha 1

    You can add a mozNoMarginBoxes attribute to the tag to prevent the URL, page numbers and other things Firefox adds to the page margin from being printed.

    It is working in Firefox 29 and onwards. You can see a screen shot of the difference here, or see here for a live example.

    Note that the mozDisallowSelectionPrint attribute in the example is not required to remove the text from the margins; see What does the mozdisallowselectionprint attribute in PDF.js do?.

    Other browsers

    Unfortunately, there seems to be no way to resolve this problem in Internet Explorer, so you'll have to resort to PDF or ask users to disable margin texts.

    The same goes for Safari; according to a comment by @Luiz Perez, the most recent versions of Safari (8, 9.1 and 10) still do not support @page for suppressing margin texts.

    I can't find anything on Edge and I don't have a Windows 10 installation available to test.

提交回复
热议问题