1.js中打印指定区域内容 兼容IE FF Google等主流浏览器
<script type="text/javascript">
function wesPrint(id_s)
{
var cc = document.getElementById(id_s).innerHTML;
var isIe=0;
if(navigator.userAgent.indexOf('MSIE')>0){
isIe = 1;
}
var frame = document.getElementById('dsh_myframe');
if (!frame) {
if (isIe) {
frame = document.createElement('<iframe id = "dsh_myframe"></iframe>');
} else {
frame = document.createElement('iframe');
frame.id ='dsh_myframe';
frame.setAttribute('style','width: 0pt; height: 0pt;')
}
}
if (isIe) {
frame.src = 'javascript:;';
frame.style.cssText= 'width: 0pt; height: 0pt;';
}
document.body.appendChild(frame);
if (isIe) {
doc = frame.contentWindow.document;
} else {
doc = frame.contentDocument;
}
doc.write(cc);
doc.close();
frame.contentWindow.focus();
if(isIe){
setTimeout(function(){
frame.contentWindow.print();
},2);
}else{
frame.contentWindow.print();
}
}
</script>
<div id="div1">Print area.....Test</div>
<button onlick="wesPrint('div1');">Print Div</button>