惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
Intezer
C
Cyber Attacks, Cyber Crime and Cyber Security
The Register - Security
The Register - Security
量子位
Security Latest
Security Latest
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
MyScale Blog
MyScale Blog
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
Jina AI
Jina AI
博客园 - 【当耐特】
P
Palo Alto Networks Blog
Last Week in AI
Last Week in AI
SecWiki News
SecWiki News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
G
GRAHAM CLULEY
宝玉的分享
宝玉的分享
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
有赞技术团队
有赞技术团队
T
Tor Project blog
H
Hacker News: Front Page
A
Arctic Wolf
NISL@THU
NISL@THU
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
V
V2EX
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
I
InfoQ
D
Docker
L
LINUX DO - 最新话题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
U
Unit 42

博客园 - Smthhy

从公司管理到IT审计-网摘 如何为PDF文件添加书签 解决WCF传输大数据量时出错并提示:远程主机强迫关闭了一个现有的连接 ARCGIS DESKTOP 安装步骤 - Smthhy ms Sql server 中的getDate()函数使用方法总结 WCF客户端调用服务 出现套接字连接已中止...... C语言中time_t到.NET的转换与更改系统时间 Thread and Sync In C# (C#中的线程与同步) sql 跨服务器查询 div自适应高度 - Smthhy - 博客园 js中event.x,event.clientX,event.offsetX区别 JS模拟出 getElementsByClassName 功能 - Smthhy jQuery对象与DOM对象之间的转换 - Smthhy - 博客园 语言代号一览表 收集 IE Flash10b.ocx加载项失败 解决 解决Aptana无高亮显示,无提示问题 ASP.NET State Service - Smthhy 尝试创建Web项目或打开位于URL“http ://localhost/WebApplication1”的Web 项目 C# winform 打印当前窗体 - Smthhy
WebBrowser 打印设置,打印预览,去页眉和页脚
Smthhy · 2009-06-18 · via 博客园 - Smthhy

WebBrowser是IE内置的浏览器控件,无需用户下载.

一、WebBrowser控件
  <object ID='WebBrowser' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>
二、WebBrowder控件的方法
//打印

WebBrowser1.ExecWB(6,1);

//打印设置

WebBrowser1.ExecWB(8,1);

//打印预览

WebBrowser1.ExecWB(7,1);

关于这个组件还有其他的用法,列举如下:
WebBrowser.ExecWB(1,1) 打开
Web.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口
Web.ExecWB(4,1) 保存网页
Web.ExecWB(6,1) 打印
Web.ExecWB(7,1) 打印预览
Web.ExecWB(8,1) 打印页面设置
Web.ExecWB(10,1) 查看页面属性
Web.ExecWB(15,1) 好像是撤销,有待确认
Web.ExecWB(17,1) 全选
Web.ExecWB(22,1) 刷新
Web.ExecWB(45,1) 关闭窗体无提示
但是打印是会把整个页面都打印出来的,页面里面有什么东西就打印出来,我们有时候只需要打印数据表格,这时我们就要写一个样式了:把不想打印的部份隐藏起来:
样式内容:
<style type="text/css" media=print>
.noprint{display : none }
</style>
然后使用样式就可以:
<p class="noprint">不需要打印的地方</p>

代码如下:

<script language="javascript">
function printsetup(){
// 打印页面设置
wb.execwb(8,1);
}
function printpreview(){
// 打印页面预览

wb.execwb(7,1);

}

function printit()
{
if (confirm('确定打印吗?')) {
wb.execwb(6,6)
}
}
</script>

<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
<input type=button name=button_print value="打印" class="noprint" onclick="javascript:printit()">
<input type=button name=button_setup value="打印页面设置" class="noprint" onclick="javascript:printsetup();">
<input type=button name=button_show value="打印预览" class="noprint" onclick="javascript:printpreview();">

----------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/javascript">  
     var HKEY_Root,HKEY_Path,HKEY_Key;   
     HKEY_Root="HKEY_CURRENT_USER";   
     HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";   
         //设置网页打印的页眉页脚为空   
     function PageSetup_Null()  
      {   
        try {   
                var Wsh=new ActiveXObject("WScript.Shell");   
        HKEY_Key="header";   
        Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");   
        HKEY_Key="footer";   
        Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");   
        }  catch(e){}   
      }   
      //恢复网页打印的页眉页脚  
      function PageSetup_default()  
      {   
        try {   
                var Wsh=new ActiveXObject("WScript.Shell");   
        HKEY_Key="header";   
        Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P");   
        HKEY_Key="footer";   
        Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d");   
        }  catch(e){}   
      }   

function printsetup(){
// 打印页面设置
wb.execwb(8,1);
}
function printpreview(){
// 打印页面预览
PageSetup_Null();
wb.execwb(7,1);

}

function printit()
{
if (confirm('确定打印吗?')) {
PageSetup_Null();
wb.execwb(6,6)
}
}

</script> 
<style type="text/css" media=print>
.noprint{display : none }
</style>
</HEAD>

<BODY>
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
<input type=button name=button_print value="打印" class="noprint" onclick="javascript:printit()">
<input type=button name=button_setup value="打印页面设置" class="noprint" onclick="javascript:printsetup();">
<input type=button name=button_show value="打印预览" class="noprint" onclick="javascript:printpreview();">
</BODY>
</HTML>

----------------------------------------------------------------------
注意有可能执行时,会出现没有效果的错误,这时原因是可能你的浏览器限制了active对象的创建,只要取消限制就好了,取消方法如下:

打开你的ie浏览器internet选项—— 安全—— 自定义级别—— 把对没有标记为安全的activex控件进行初始化和脚本运行 设置为启用