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

后端 未结 9 813
生来不讨喜
生来不讨喜 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 09:13

    I have a similar request from a client who wants to have the header, page numbers, and html footer removed. In this case, the client is presenting an HTML page that can double as a formal certificate. The added URL, page, and, header, are irrelevant and lead to a less-than-pleasing final product. In some ways, it just looks cheap.

    Media=Print has not been able to disable these browser defaults. The only workaround is to tell the user to click the "Gear" button and toggle those items on/off. Seriously, I had no idea I could do that for 20 years (and we think the typical user will have a clue to click the toggle button?).

    If CSS supports Media=Print, it should support the ability to control the entire end-user print experience. I appreciate that the browsers provide the added fields, but, why not allow CSS to control the overall print experience-if that is what's desired. A 90% solution could be 100% with three more fields! A simple:

    #BrowserPrintDefaults{display:none} 
    

    would suffice.

    Again, it's not a matter whether or not the end-user wants to print it out or not (maybe your client is very private and doesn't want printed URLs floating around. Or maybe a executive team uses a private collaboration sites?). Glad to defend the end-user, but if somebody is seeking an answer, don't respond saying it's the right of the end-user to show or hide. Sometimes it's the right of the client paying the bills.

    0 讨论(0)
  • 2020-11-22 09:16

    @page margin:0mm now works in Firefox 19.0a2 (2012-12-07).

    0 讨论(0)
  • 2020-11-22 09:18

    As @Awe had said above, this is the solution, that is confirmed to work in Chrome!!

    Just make sure this is INSIDE the head tags:

    <head>
    <style media="print">
        @page 
        {
            size: auto;   /* auto is the initial value */
            margin: 0mm;  /* this affects the margin in the printer settings */
        }
    
        body 
        {
            background-color:#FFFFFF; 
            border: solid 1px black ;
            margin: 0px;  /* this affects the margin on the content before sending to printer */
       }
    </style>
    </head>
    
    0 讨论(0)
提交回复
热议问题