情况:为了打印出其他iframe页面内容,而我的情况,则是打印出同一个tomcat下的其他应用程序的页面(此处可以操作其他页面的window,是由于没有跨域问题,如果是跨域问题的话,除非两边都能有权限设置,否则GG,而现在再同一个tomcat下,所以IP和端口号都一致,无跨域问题。)
代码:
//打印简历
function printResume(){
var resumeWindow = document.getElementById("resumeInfo").contentWindow;
var go = confirm("是否需要打印?");
if(go){
if(!window.showModalDialog){
resumeWindow.print();
}else{
//兼容IE8,不加前面这两句,只能打印出整个页面的预览效果,并不是简历原件的内容
resumeWindow.document.body.className += ' ext-ie';
resumeWindow.document.execCommand('print', false, null);
resumeWindow.print();
}
}
}
页面代码:
<body>
<div class="div_btn">
<input type="button" onclick="printResume()" value="打印">
</div>
<div id="div">
<iframe id="resumeInfo" class="resumeInfo" src="${url }"/>
</div>
</body>
参考: