利用javascript打印html网页内容中的指定内容
2014-07-30 17:22
330 查看
之前帮老师做一个小模块,需要有一个是打印功能,我就在网上找了很多材料,其中一个方法是通过javascript打印网页中的指定内容,这个方法相对来说比较简单,但是,只要能够完成需求,它就是一个好方法。
具体的代码如下,我是写在jsp页面中的,当然,也可以应用在其他例如html或者asp等。
<head>
<script language="JavaScript">
<!--
function doPrint() {
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();
location.reload();
}
//-->
</script>
</head>
<body>
<!--startprint-->
<table width="700" align="left" border="1">
<tr>
<td>待打印的内容</td>
</tr>
</table>
<!--endprint-->
<input type="button" onclick="doPrint()">
</body>
具体的代码如下,我是写在jsp页面中的,当然,也可以应用在其他例如html或者asp等。
<head>
<script language="JavaScript">
<!--
function doPrint() {
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();
location.reload();
}
//-->
</script>
</head>
<body>
<!--startprint-->
<table width="700" align="left" border="1">
<tr>
<td>待打印的内容</td>
</tr>
</table>
<!--endprint-->
<input type="button" onclick="doPrint()">
</body>
相关文章推荐
- 直接调用window.print将打印网页上的指定内容
- js网页打印指定区域内容
- 利用PyQt抓取含有JavaScript执行结果的网页内容?
- android利用http协议下载网页内容到指定位置的方法
- [Python]网络爬虫(二):利用urllib2通过指定的URL抓取网页内容
- 使用javascript对网页的部分内容进行打印
- 原创]HTML网页间利用JavaScript通过URL传递变量
- Javascript实现打印网页中定义的部分内容
- 利用HtmlParse抽取网页正文内容
- [Python]网络爬虫(二):利用urllib2通过指定的URL抓取网页内容
- javascript: 加亮指定的文章内容关键字网页特效代码
- 打印html中指定内容
- 使用javascript去掉打印网页时页眉与页脚的内容
- 使用javascript对网页的部分内容进行打印
- js php打印网页中指定的部分内容和范围
- 利用javascript向静态html网页传递参数
- javascript打印指定div内容
- javascript 网页指定区域打印函数
- 【HTML】使用iframe标签显示目标网页(内容)的指定区域
- JavaScript 打印网页内容