转自学网(http://www.xue5.com/itedu/200802/102909.html)

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 XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>打印设置</title>
<link rel="stylesheet" media="screen" type="text/css" href="http://www.chinasvf.com/Webs/public/default/css/bank.css" />
<!-- 打印样式 -->
<link rel="stylesheet" media="print" type="text/css" href="http://www.chinasvf.com/Webs/public/default/css/bankprint.css" />
<script language="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 RegWsh = new ActiveXObject("WScript.Shell");
hkey_key="header";
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");
hkey_key="footer";
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");
//&b 第&p页/共&P页 &b
}catch(e){}
}
//配置网页打印的页眉页脚为默认值
function pagesetup_default(){
try{
var RegWsh = new ActiveXObject("WScript.Shell");
hkey_key="header";
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P")
hkey_key="footer";
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&u&b&d");
}catch(e){}
}
//打印选区内容
function doPrint() {
pagesetup_null();
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
}
//打印页面预览
function printpreview(){
pagesetup_null();
//wb.printing.header = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页";
//wb.printing.footer = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页";
try{
wb.execwb(7,1);
}catch(e){
alert("您的浏览器不支持此功能,请选择'文件'->'打印预览'");
}
}
//打印
function prints(){
pagesetup_null();
//wb.printing.header = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页";
//wb.printing.footer = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页";
try{
wb.execwb(6,1);
}catch(e){
alert("您的浏览器不支持此功能");
}
}
</script>
</head>
<body>
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" id="wb" width="0" height="0"></OBJECT>
<div id="bankwrap">
<div class="Noprint"><a href="http://www.chinasvf.com" style="cursor:pointer; color:#0000FF">返回首页</a></div>
<div style="text-align:right">
<p class="Noprint">
<span style="cursor:pointer; color:#0000FF" onclick="javascript:window.open('http://www.chinasvf.com/Webs/Share/printhelp')" class="Noprint">打印帮助</span>
<span style="cursor:pointer; color:#0000FF" onclick="printpreview();">打印预览</span>
<span style="cursor:pointer; color:#0000FF" onclick="prints();" class="Noprint">打印</span>
</p>
</div>
<div class="banktitle">内容</div>
</div>
</body>
</html>

js 调用IE内置打印控件的更多相关文章

  1. AE内置Command控件使用

    樱木 原文 AE内置Command控件使用 直接使用AE内置的Command控件来完成功能 1.拉框放大 /// <summary> /// 放大 /// </summary> ...

  2. JS调用Android、Ios原生控件

    在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...

  3. Phonegap 之 iOS银联在线支付(js调用ios端银联支付控件)

    Phonegap项目,做支付的时候,当把网站打包到ios或android端成app后,在app上通过wap调用银联在线存在一个问题: 就是当从银联支付成功后,再从服务器返回到app客户端就很难实现. ...

  4. JS调用Delphi编写的OCX控件

    原文:http://www.mamicode.com/info-detail-471283.html 一.使用Delphi XE2编写OCX控件 生成OCX工程: 1.File-New-Other,在 ...

  5. 推荐内置android控件的开源项目alcinoe

    开源地址:https://github.com/Zeus64/alcinoe 该控件包,含以下几个控件: 1.基于OpenGL实现的视频播放器 ALVideoPlayer. ALVideoPlayer ...

  6. 基于MVC4+EasyUI的Web开发框架经验总结(16)--使用云打印控件C-Lodop打印页面或套打报关运单信息

    在最新的MVC4+EasyUI的Web开发框架里面,我整合了关于网购运单处理的一个模块,其中整合了客户导单.运单合并.到货扫描.扣仓.出仓.查询等各个模块的操作,里面涉及到一些运单套打的操作,不过由于 ...

  7. Arcgis API for JS——打印控件乱码

    在通过Arcgis API for JS编写打印控件进行地图下载时,总发现地图字体乱码,如下图: 解决方法: 在装有ArcGIS Server,要调用服务的电脑或服务器上找到下图文件夹

  8. C/S架构引用Lodop 如何在C#调用web打印控件Lodop

    lodop是web打印控件,引用安装目录下的ocx文件,可以在c/s架构中使用. 该文件所在路径:C:\Program Files (x86)\MountTaiSoftware\Lodop 有32位和 ...

  9. 网页WEB打印控件制作-开放源码

    在WEB系统中,打印的确是比较烦人的问题,如果我们能制作一个属于自己的自定义的打印插件,那么我们在后续自定义打印的时候能随心所欲的控制打印,这样的效果对于程序员来说是非常开心的一件事件,本文将自己开发 ...

随机推荐

  1. GoLang安装

    GoLang的官网被墙,镜像下载地址:http://tip.golang.so/dl/  或者 http://golang.so/dl/ 安装说明:http://tip.golang.so/doc/i ...

  2. [Linux] Ubuntu Server 12.04 LTS 平台上搭建WordPress(Nginx+MySql+PHP) Part II

    接着上一节继续搭建我们的LNMP平台,接下来我们安装PHP相关的服务 sudo apt-get install php5-cli php5-cgi php5-fpm php5-mcrypt php5- ...

  3. 表格控件表头栏目(Column)与数据表头步

    不用手工增加栏目的列,也就是Column,由数据库的查询结果自动创建. 用的是Delphi2010,安装了Dev,用CxGrid显示数据库查询结果.用什么控件没有关键,道理相同的.

  4. .Net并行编程

    1.什么是线程?线程和进程的区别是什么? 线程是程序执行的最小单元. 区别: 进程是操作系统进行资源处理和分配的最小单位,而一个进程可以包含多个线程,并共享进程的资源. 2.什么是多线程?为什么设计多 ...

  5. Server Tomcat v7.0 Server at localhost failed to start解决办法

    今晚搞了下tomcat,在调试的时候发现报了这样一个错误Server Tomcat v7.0 Server at localhost failed to start 首先,确认了端口号8080是不是被 ...

  6. 第一步 django的下载安装

    django是python众多web框架中比较有名的一个,以大包大揽功能俱全而著名.但作为重量级的web框架,难免性能上回有所损失,不过由于其封装了各种API,在开发的时候会便利许多.所以也是深受欢迎 ...

  7. IE10-浏览器实现placeholder效果

    如下图,在文本框为空时显示提示文字 在IE10+和chrome浏览器加placeholder属性及可实现 ,单在IE10-浏览器并不支持该属性, 以下是placeholder在IE10-浏览器的实现 ...

  8. javascript中方法调用与方括号[]

    看jquery时遇到一行: $(this)["removeClass"]("selected"); 这一行等同于下面的一行: $(this).removeCla ...

  9. hdu 1908 Double Queue

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1908 Double Queue Description The new founded Balkan ...

  10. 基于perl的网络爬虫

    use Mojo::UserAgent; use Bloom::Filter; use Smart::Comments; use DBI; my $dbname = "bbs_url&quo ...