没有合适的资源?快使用搜索试试~ 我知道了~
1、程序说明1) 此程序可以实现选择页面中的区域进行打印,以iframe方式进行打印;2) 与原生态的print() 区别在于,取消打印页面后可以完整保留当前访问页面的内容。2、代码部分 1) JS 函数: 代码如下:function do_print(id_str)//id-str 打印区域的id{var el = document.getElementById(id_str);var iframe = document.createElement(‘IFRAME’);var doc = null;iframe.setAttribute(‘style’, ‘position:absolut
资源推荐
资源详情
资源评论
js调用调用iframe实现打印页面内容的方法实现打印页面内容的方法
1、程序说明
1) 此程序可以实现选择页面中的区域进行打印,以iframe方式进行打印;
2) 与原生态的print() 区别在于,取消打印页面后可以完整保留当前访问页面的内容。
2、代码部分
1) JS 函数:
代码如下:
function do_print(id_str)//id-str 打印区域的id
{
var el = document.getElementById(id_str);
var iframe = document.createElement(‘IFRAME’);
var doc = null;
iframe.setAttribute(‘style’, ‘position:absolute;width:0px;height:0px;left:-500px;top:-500px;’);
document.body.appendChild(iframe);
doc = iframe.contentWindow.document;
// 引入打印的专有CSS样式,www.111Cn.net根据实际修改
doc.write(“<LINK rel=”stylesheet” type=”text/css” href=”css/print.css”>”);
doc.write(‘<div>’ + el.innerHTML + ‘</div>’);
doc.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();
if (navigator.userAgent.indexOf(“MSIE”) > 0)
{
document.body.removeChild(iframe);
}
}
2) HTML:
代码如下:
// 打印区域:
<div id=”print_box”>
……
</div>
// 调用打印
<button onclick=”javascript:do_print(‘print_box’);”>打印</button>
3. 测试
点击页面上的打印按钮,即可测试打印;
除了上面方法我们还可以通过jquery来实例,代码如下
代码如下:
<script type=”text/javascript” src=”jquery-1.4.2.min.js”></script>
<script type=”text/javascript” src=”jquery.PrintArea.js”></script>
<script>
$(document).ready(function(){
$(“input#biuuu_button”).click(function(){
$(“div#myPrintArea”).printArea();
});
});
</script>
资源评论
weixin_38660327
- 粉丝: 8
- 资源: 953
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功