更改Chrome打印预览默认选项 [英] change chrome print preview default options

查看:1802
本文介绍了更改Chrome打印预览默认选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Chrome打印预览中,在选项选项卡下,默认情况下打开了页眉和页脚。是否可以通过javascript / chrome扩展/设置默认关闭/告诉用户手动执行它?



或者是否可以删除在那里显示的日期?



解决方案

总之,是的,您可以控制这种行为。这实际上是非常bizzarre - 看起来最初在问题 说:


页面框是一个包含两个区域的矩形区域:


  • 页面区域。页面区域包括该页面上显示的框。
    第一页区域的边缘建立矩形,该矩形是包含文档块的
    初始值。画布背景为
    ,并覆盖页面区域。


  • 页边空白区域,其中
    环绕页面区域。



大多数现代浏览器支持 @page CSS属性。尽管Firefox完全将文档记录在其中开发者资源和他们的问题跟踪器有一个这样的票那可以追溯到10年。最近的行动是在今天,所以FF很快就会提供 @page 支持。


In chrome print preview, under Options tab, the default is having Headers and footers ticked on. Is it not possible to set it default to off via javascript / chrome extension / anything outside telling user to do it manually?

OR is it possible to remove the date displayed there?

解决方案

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.

这篇关于更改Chrome打印预览默认选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆