更改chrome打印预览默认选项

hxzsmxv2  于 2022-12-06  发布在  Go
关注(0)|答案(7)|浏览(519)

在chrome打印预览中,在“选项”选项卡下,默认情况下是勾选页眉和页脚。是否不可能通过javascript / chrome扩展/任何外部命令手动将其设置为默认关闭?
或者是否可以删除显示的日期?

zwghvu4y

zwghvu4y1#

In short, yes you can control this behavior. It is actually very bizzarre -- as appears to have been originally answered in the question "In Google Chrome, Docs Can Control Headers and Footers from Javascript?" The secret to this behavior is in the @page CSS property*.
If you set this exact style:

@page { margin: 0; }

Then you get the desired behavior, the headers & footers option disappears:

This appears to be an undocumented behavior of Google Chrome, or at least not widely known -- cursory digging in to their developer docs garnered nothing. Google uses it themselves throughout their own web-apps, so it's probably not a secret, but I couldn't find any official notes on it.
Notably, a margin of 0 does not simply disable the "headers & footers" option, it actually causes it to disappear from the menu entirely ( by quickly folding ).
Experimentation reveals that other variations of this do not have the same effect. For example margin: 0; margin-left: 10cm; does not cause this behavior.
If you do choose to implement this solution, it means forfeiting the ability to control those margins through the @page property -- you should instead be controlling them as part of a CSS print-media stylesheet. Bummer that Chrome kind of destroys the @page property this way. That said, FF still does not support @page ( as of now ) so it's not a perfect solution to begin with.

  • More information about the @page property

The @page CSS is supposed to control the margins of the printed page, the specification says:
The page box is a rectangular region that contains two areas:

  • The page area. The page area includes the boxes laid out on that page. The edges of the first page area establish the rectangle that is the initial containing block of the document. The canvas background is painted within and covers the page area.
  • The margin area, which surrounds the page area. The page margin area is transparent.

Most modern browsers support the @page CSS property. Firefox is the standout who doesn't, though they do fully document it in their developer resources , and their issue tracker has a ticket for this that goes back 10 years. The most recent action on it was today, so perhaps FF will provide @page support soon.

llew8vvj

llew8vvj2#

这个页面只是html,所以如果你可以在页面上执行javascript,那么你就可以做到这一点。我不记得Chrome扩展是否可以绑定到内部页面。你知道如何编写Chrome扩展吗?如果知道,这将是很容易测试。

document.getElementById('header-footer').checked = false;
mm5n2pyu

mm5n2pyu3#

Chrome只允许你override耦合特定的chrome://页面,打印页面不是其中之一。你也被限制为injecting脚本到一对夫妇的特定方案。
匹配模式实质上是以允许的方案(http、https、file或ftp)开头的URL

yhxst69z

yhxst69z4#

在当前版本的谷歌浏览器中,打印预览现在可以选择是否包含页眉和页脚,以及定义边距和是否包含背景颜色和图像。只需将浏览器更新到最新版本。

ssm49v7z

ssm49v7z5#

当前版本的31记得设置是否你想要它的双面,页眉和页脚和打印的背景图像和颜色,但据我所知,它不会记得边距设置。

baubqpgj

baubqpgj6#

来自https://excessivelyadequate.com/posts/print.html的代码模板已测试并正常工作

@page {
    /* Browser default, customizable by the user in the print dialogue. */
    size: auto;

    /* Default, but explicitly in portrait or landscape orientation and not user-
    customizable. In my instance of Chrome, this is a vertical or horizontal letter
    format, but you might find something different depending on your locale. */
    size: portrait;
    size: landscape;

    /* Predefined format, can be coupled with an orientation. */
    size: letter;
    size: A4;
    size: A4 landscape;

    /* Custom, with same width and height. */
    size: 10cm;
    size: 420px;
    size: 6in;

    /* Different width and height. */
    size: 640px 360px;
    size: 20cm 15cm;
}
neekobn8

neekobn87#

看来这件事是没有办法了。

相关问题