打印机友好的页面使用Response.Write

本文关键字:Response Write 打印机 | 更新日期: 2023-09-27 18:07:55

我需要创建一个打印友好的页面,只包含几个数据字段从我的单页网站。我被告知要通过使用Response.Write来做到这一点。

我在任务中得到了这样的提示:

技巧是使用Response方法,该方法由Page提供类(更准确地说,它是由父类提供的)System.Web)。您在屏幕上显示的内容是由System.Web管理的对象,并使用Response方法,您可以放入任何您想要的东西在那里。

我在谷歌上搜索了一下,但这似乎不像应该这样做,但出于某种原因,它必须这样做。

基本上它必须创建一个打印友好的页面,通过清除页面和传递只有一些变量,以显示纯黑色在白色。

打印机友好的页面使用Response.Write

我被告知通过使用Response.Write来做到这一点。

无论谁叫你这样做都是错的,错的,错的。

如果你需要制作任何类型的网页"打印机友好",那么正确的方法是通过媒体查询

如果你的页面现在有这样的CSS

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

然后您只需创建第二个样式表,它可以完成使页面"打印机友好"所需的一切,然后更改html以包含print版本。

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

然后在print.css样式表中,您可以使用与打印视图直接相关的样式。在这个链接

中可以找到一些例子。
/*Make your layout similar to a sheet of paper*/
body, #content, #container {
    width: 100%;
    margin: 0;
    float: none;
    background: #fff url(none);
}
/*Hide navigation, ads, and anything else you don't want printed*/
#topnav, #navbar, #nav, #sidebar, .ad, .noprint {
    display: none; 
}
/*Set a new default font*/
body {
    font: 1em Georgia, "Times New Roman", Times, serif;
    color: #000; 
}
/*Style your headings*/
h1,h2,h3,h4,h5,h6 {
    font-family: Helvetica, Arial, sans-serif;
    color: #000;
}
h1 { font-size: 250%; }
h2 { font-size: 175%; }
h3 { font-size: 135%; }
h4 { font-size: 100%; font-variant: small-caps; }
h5 { font-size: 100%; }
h6 { font-size: 90%; font-style: italic; }
/*Display the links associated with hyperlinks*/
a:link, a:visited {
    color: #00c;
    font-weight: bold;
    text-decoration: underline; }
#content a:link:after, #content a:visited:after {
    content: " (" attr(href) ") ";
}