Html 如何从打印页面中删除 URL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/585254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:20:12  来源:igfitidea点击:

How to remove the URL from the printing page?

htmlprintingfooter

提问by Chamika Sandamal

I want to remove the URL that gets printed on the bottom of the page.

我想删除打印在页面底部的 URL。

like:

喜欢:

yomari.com/.../main.php?sen_n

How can it be omitted or prevent from getting printed?

如何省略或防止打印?

To be more specific, is there any way I can prevent the page URL, date and the page title being printed along, while printing the web page?

更具体地说,有什么方法可以在打印网页时阻止页面 URL、日期和页面标题一起打印?

回答by Chamika Sandamal

Following code sample will work for you,

以下代码示例对您有用,

<style type="text/css" media="print">
@page {
    size: auto;   /* auto is the initial value */
    margin: 0;  /* this affects the margin in the printer settings */
}
</style>

see the answer on Disabling browser print options (headers, footers, margins) from page?

请参阅从页面禁用浏览器打印选项(页眉、页脚、页边距)的答案

and specification of the @page

@page的规范

回答by Jah Yusuff

i found something in the browser side itself.

我在浏览器端发现了一些东西。

Try this steps. here i have been mentioned the Steps to disable the Header and footer in all the three major browsers.

试试这个步骤。在这里我已经提到了在所有三个主要浏览器中禁用页眉和页脚的步骤。

ChromeClick the Menu icon in the top right corner of the browser. Click Print. Uncheck Headers and Footers under the Options section.

Chrome单击浏览器右上角的菜单图标。单击打印。取消选中选项部分下的页眉和页脚。

FirefoxClick Firefox in the top left corner of the browser. Place your mouse over Print, the click Page Setup. Click the Margins & Header/Footer tab. Change each value under Headers & Footers to --blank--.

Firefox单击浏览器左上角的 Firefox。将鼠标放在“打印”上,单击“页面设置”。单击边距和页眉/页脚选项卡。将页眉和页脚下的每个值更改为 --blank--。

Internet ExplorerClick the Gear icon in the top right corner of the browser. Place your mouse over Print, then click Page Setup. Change each value under Headers and Footers to -Empty-.

Internet Explorer单击浏览器右上角的齿轮图标。将鼠标放在“打印”上,然后单击“页面设置”。将页眉和页脚下的每个值更改为 -Empty-。

回答by Rowland Shaw

Having the URL show is a browser client preference, not accessible to scripts running within the page (let's face it, a page can't silently print themselves, either).

显示 URL 是浏览器客户端的首选项,页面内运行的脚本无法访问(让我们面对现实,页面也不能静默打印自己)。

To avoid "leaking" information via the query string, you could submit via POST

为避免通过查询字符串“泄露”信息,您可以通过 POST 提交

回答by Denver Chiwakira

If you set the margin for a page using the code below the header and footers are omitted from the printed page. I have tested this in FireFox and Chrome.

如果您使用下面的代码设置页面边距,则打印页面中将省略页眉和页脚。我已经在 FireFox 和 Chrome 中对此进行了测试。

<style media="print">
 @page {
  size: auto;
  margin: 0;
       }
</style>

回答by Mitravind Garg

I am telling you about Mozilla Firefox ( I hope it should be same way in other browsers also).

我告诉你关于 Mozilla Firefox(我希望它在其他浏览器中也应该是相同的)。

Click on Firefox menu, Go to Print, Select Page Set Upfrom sub menu of Print. A pop will come up on your screen, there go to "Margin & Header /Footer"tab.

单击Firefox 菜单,转到打印,从打印的子菜单中选择页面设置。屏幕上会弹出一个弹出窗口,转到“边距和页眉/页脚”选项卡。

In that select "BLANK"for header / footer as per requirement before printing. You can check the preview for confirmation.

在打印之前,根据要求为页眉/页脚选择“空白”。您可以查看预览进行确认。

I hope this will help.

我希望这将有所帮助。

回答by mihaela

This helped me: Print page without links

这对我有帮助: 打印没有链接的页面

@media print {
    a[href]:after {
        content: none !important;
    }
}

回答by Anju

You can remove the url dispalying on the printed document via your browser settings.You just click file->page setup->header and footer set all things as blank.if you hav ie,you just remove &U from footer textbox.hopefully this will help you

您可以通过浏览器设置删除打印文档上显示的 url。您只需单击文件->页面设置->页眉和页脚将所有内容都设置为空白。如果您有 IE,您只需从页脚文本框中删除 &U。希望这会帮你

回答by ólafur Waage

I do not know if you are talking about a footer within your actual graphic or the url the print process within the browser is doing.

我不知道您是在谈论实际图形中的页脚还是浏览器中的打印过程正在执行的 url。

If its the url the print process is doing its really up to the browser if he has a feature to turn that off.

如果它是 url,则打印过程实际上取决于浏览器,如果他有关闭它的功能。

If its the footer information i would recommend using a print stylesheet and within that stylesheet to do

如果是页脚信息,我建议使用打印样式表并在该样式表中执行

display: none;

For the particular ID or class of the footer.

对于页脚的特定 ID 或类。

To do a print stylesheet, you need to add this to the head.

要打印样式表,您需要将其添加到头部。

<link rel="stylesheet" type="text/css" href="/css/print.css" media="print" />

回答by Ardee Aram

In Google Chrome, this can be done by setting the margins to 0, or if it prints funky, then adjusting it just enough to push the unwanted text to the non-printable areas of the page. I tried it and it works :D

在谷歌浏览器中,这可以通过将边距设置为 0 来完成,或者如果它打印出时髦,然后将其调整到足以将不需要的文本推送到页面的不可打印区域。我试过了,它有效:D

enter image description here

在此处输入图片说明

回答by James Yang

Nowadays, you can use history APIto modify the URL before print, then change back:

现在,您可以使用history API在打印前修改 URL,然后更改回来:

var curURL = window.location.href;
history.replaceState(history.state, '', '/');
window.print();
history.replaceState(history.state, '', curURL);

But you need to make a custom PRINTbutton for user to click.

但是您需要制作一个自定义PRINT按钮供用户单击。