如何使用代码删除打印页眉/页脚 [英] how to remove print header/footer with code

查看:75
本文介绍了如何使用代码删除打印页眉/页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码在我的应用程序中打印页面...

I am using the following code to print a page within my application...

<html><body onload=""window.print();"">"
  sHtmlBody = sHtmlBody & "<body>"

window.print()工作正常。
我知道一旦打印出现我可以手动进入设置并删除页眉和页脚。
在IE上我知道我必须打印预览然后删除打印标题。

The window.print() is working fine. I know once the print comes up I can manually go into the settings and remove headers and footer. On IE I know that I have to go to print preview and then remove the print headers.

但是,是否有一些行自动执行此操作的代码,以便应用程序的用户不必执行此操作?

However, is there some line of code which does this automatically so the users of the application don't have to do this?

编辑:

 sHtmlBody = "<style type='text/css'>"
      sHtmlBody = sHtmlBody & " @media print{"
      sHtmlBody = sHtmlBody & " body{ background-color:#FFFFFF; background-image:none; color:#000000 }"
      sHtmlBody = sHtmlBody & " #ad{ display:none;}"
      sHtmlBody = sHtmlBody & " #leftbar{ display:none;}"
      sHtmlBody = sHtmlBody & " #contentarea{ width:100%;}"
      sHtmlBody = sHtmlBody & " }"
      sHtmlBody = sHtmlBody & " </style>"
      sHtmlBody = sHtmlBody & "<html><body onload=""window.print();"">"
      sHtmlBody = sHtmlBody & "<body>"


推荐答案

你可以在CSS的帮助下,在打印之前设置页面的CSS。例如:

you can do with the help of CSS , before print set the CSS of the page . for example:

<style type="text/css">
@media print{
  body{ background-color:#FFFFFF; background-image:none; color:#000000 }
  #ad{ display:none;}
  #leftbar{ display:none;}
  #contentarea{ width:100%;}
}
</style>

此代码何时添加到页面隐藏2个div与idsad和leftba r,加上在打印时对文档的其余部分进行其他更改。

This code when added to the page hides the 2 divs with ids "ad" and "leftbar", plus makes additional changes to the rest of the document when it's printed.

如果您询问浏览器特定设置,如打印日期和时间,
那么我认为通过代码是不可能的。看看这个:
删除默认浏览器打印HTML时页眉和页脚

IF you are asking about browser specific settings like print date and time , then i think it is not possible through code. check this out : Remove the default browser header and footer when printing HTML

这篇关于如何使用代码删除打印页眉/页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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