禁用浏览器打印选项(页眉,页脚,页边距)从页面? [英] Disabling browser print options (headers, footers, margins) from page?

查看:567
本文介绍了禁用浏览器打印选项(页眉,页脚,页边距)从页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了这个问题,在SO和其他一些网站的几个不同的方式问,但其中大部分不是太具体或外的日期。我希望有人可以在这里提供一个明确的答案,而不迎合投机。

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 can provide a definitive answer here without pandering to speculation.

有没有一种方法,无论是与CSS或JavaScript,更改默认的打印机设置,当有人浏览器内打印?当然是从他们的浏览器打印的我的意思是某种形式的HTML,PDF没有或其他一些插件依赖MIME类型。

Is there a way, either with CSS or javascript, to change the default printer settings when someone prints within their browser? And of course by "prints from their browser" I mean some form of HTML, not PDF or some other plug-in reliant mime-type.

请注意:

如果一些浏​​览器提供这种和别人不一样(或者,如果你只知道怎么做了一些浏览器)我欢迎浏览器特定的解决方案。

If some browsers offer this and others don't (or if you only know how to do it for some browsers) I welcome browser-specific solutions.

同样,如果您知道有针对EVER这样做具体限制主流浏览器,这也是有益的,但​​一些相当先进的最新文档将AP preciated。 (简单地说:这违背了XYZ的安全策略,是不是很有说服力,当XYZ取得了显著的变化表示,在过去的三年策略)。

Similarly, if you know of a mainstream browser that has specific restrictions against EVER doing this, that is also helpful, but some fairly up-to-date documentation would be appreciated. (simply saying "that goes against XYZ's security policy" isn't very convincing when XYZ has made significant changes in said policy in the last three years).

最后,当我说改变默认打印设置我不意味着永远,只是我的网页,我特别是指打印边距,页眉和页脚。

Finally, when I say "change default print settings" I don't mean forever, just for my page, and I am referring specifically to print margins, headers, and footers.

我很清楚,CSS提供了改变页面方向的选择以及页边距。其中的许多斗争是Firefox浏览器。如果我设置页边距为1英寸,但其加入到半英寸就已经提出到位。

I am very aware that CSS offers the option of changing the page orientation as well as the page margins. One of the many struggles is with Firefox. If I set the page margins to 1 inch, it ADDS this to the half inch it already puts into place.

我非常想减少我的客户的网站PDF的用法,但在presentation侵权(以及缺乏可靠性)是他们的主要关注点。

I very much want to reduce the usage of PDFs on my client's site, but the infringement on presentation (as well as the lack of reliability) are their main concern.

推荐答案

在CSS标准使一些高级格式化。有一个在CSS中 @页指令,使某些格式仅适用于纸质媒介(如纸)。见<一href=\"http://www.w3.org/TR/1998/REC-CSS2-19980512/page.html\">http://www.w3.org/TR/1998/REC-CSS2-19980512/page.html.

The CSS standard enables some advanced formatting. There is a @page directive in CSS that enables some formatting that applies only to paged media (like paper). See http://www.w3.org/TR/1998/REC-CSS2-19980512/page.html.

不足之处是在不同的浏览器这种行为并不一致。 Safari浏览器仍然不支持打印机的设置页边距所有,但其他所有的主流浏览器现在支持它。

Downside is that behavior in different browsers is not consistent. Safari still does not support setting printer page margin at all, but all the other major browsers now support it.

随着 @页指令,您可以指定页面的打印边距(这是不一样的HTML元素的CSS正常利润率):

With the @page directive, you can specify printer margin of the page (which is not the same as normal CSS margin of an HTML element):

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Print Test</title>
    <style type="text/css" media="print">
    @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 */
    }
    </style>
</head>
<body>
  <div>Top line</div>
  <div>Line 2</div>
</body>
</html>

这不起作用在火狐3.6 IE 7 Safari浏览器5.1.7 谷歌浏览器4.1

设置@页边距确实有 IE 8 歌剧院10 谷歌Chrome浏览器21 火狐19 。结果
虽然页边距是为在这些浏览器内容设置正确,行为是不是在试图解决的页眉/页脚的隐藏的理想。

Setting the @page margin does have effect in IE 8, Opera 10, Google Chrome 21 and Firefox 19.
Although the page margins are set correctly for your content in these browsers, the behavior is not ideal in trying to solve the hiding of the header/footer.


  • 的Internet Explorer 后,保证金实际上是设置在该打印的设置到0mm,如果你这样做preVIEW你会得到0毫米为默认值,但用户可以改变它在preVIEW。结果
    你会看到页面内容居然都是的定位的正确,但浏览器打印页眉和页脚显示与非透明背景,因此有效地隐藏在该位置的页面内容。

  • In Internet Explorer, the margin is actually set to 0mm in the settings for this printing, and if you do Preview you will get 0mm as default, but the user can change it in the preview.
    You will see that the page content actually are positioned correctly, but the browser print header and footer is shown with non-transparent background, and so effectively hiding the page content at that position.

火狐新版本,它的定位成的正确,但页眉/页脚文字和内容文本都显示出来,所以它看起来像一个糟糕的组合浏览器标题文本和您的网页内容。

In Firefox newer versions, it is positioned correctly, but both the header/footer text and content text is displayed, so it looks like a bad mix of browser header text and your page content.

歌剧后,页面内容使用标准的CSS不透明的背景与内容页眉/页脚位置冲突时隐藏标题。相当不错,但如果边距设置到使头部分可见一个很小的值看起来很奇怪。另外,页边距设置不正确。

In Opera, the page content hides the header when using a non-transparent background in the standard css and the header/footer position conflicts with content. Quite good, but looks strange if margin is set to a small value that causes the header to be partially visible. Also the page margin is not set properly.

Chrome浏览器新版本,浏览器的页眉和页脚如果@页边距设置如此之小是隐藏与内容页眉/页脚位置冲突。在我看来,这正是这个应该如何行为。

In Chrome newer versions, the browser header and footer is hidden if the @page margin is set so small that the header/footer position conflicts with content. In my opinion, this is exactly how this should behave.

所以得出的结论是, Chrome浏览器有这个就最好落实隐藏页眉/页脚。

So the conclusion is that Chrome has the best implementation of this in respect to hiding the header/footer.

这篇关于禁用浏览器打印选项(页眉,页脚,页边距)从页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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