我尝试使用window.print()进行打印,除了ie8和ie9之外,它在所有浏览器中都能正常工作。 我在Microsoft支持网站上看到了解决方案,但由于安全原因,它们对我没用。 它在兼容模式下尝试ie8或ie9时有效,但在实际ie8或ie9中它不起作用。 我该如何解决?
我的代码:
<script type="text/javascript" language="JavaScript">
function scaleTo(scale)
{
if (isNaN(scale))
return;
//----resetting rotation before scale-----
var ang = jQuery('#rotAngle').val();
rotateReset();
var newScale = scale / currentScale;
currentScale = scale;
var image = jQuery('.imageOfPage').find("image");
var isIE = true;
if (image === null || image === undefined || image.length === 0)
{
isIE = false
image = jQuery('.imageOfPage');
}
var newWidth = newScale * image.width();
var newHeight = newScale * image.height();
if (isIE)
{
newWidth -= 2;
newHeight -= 2;
}
image.width(newWidth);
//_____________________________________________________
var browserName;
// In Chrome
if (navigator.userAgent.indexOf("Chrome")!=-1) {
browserName = "Chrome";
} // In Microsoft internet explorer
else if (navigator.userAgent.indexOf("MSIE")!=-1) {
browserName = "Microsoft Internet Explorer";
} // In Firefox
else if (navigator.userAgent.indexOf("Firefox")!=-1) {
browserName = "Firefox";
}
var msie=navigator.userAgent.indexOf("MSIE");
var version=navigator.userAgent.substring(msie+5,msie+9);
if(browserName=="Microsoft Internet Explorer"){
if( version=="11.0" ){
var newWidth =image.width();
var newHeight =image.height();
}
image.height(newHeight);
}
}
function fitTo(width, height)
{
var imageWidth = jQuery('.imageOfPage').width();
var imageHeight = jQuery('.imageOfPage').height();
var scaleX = (width * currentScale ) / imageWidth;
var scaleY = (height * currentScale ) / imageHeight;
var scale = Math.max(scaleX, scaleY);
scaleTo(scale);
}
function fitToA4()
{
var A4Width = 595;
var A4Height = 842;
fitTo(A4Width,A4Height);
}
</script>
<body>
<div id="imageWindow" style="width: 100%; height: 100%">
<%
for (int i = 0; i < pageCount; i++)
{
%>
<div style="text-align:center;width: 100%; height: 100%"
id="parentContainer<%=i%>"
class="parentContainer">
<img alt="image" id="imageOfPage<%=i%>" src="<%=imageList.get(i)%>" class="imageOfPage">
</div>
<%
}
%>
</div>
<input type="image" src="/miiroresources/images/paging_image/printerA4.png" value="Print A4"
onclick="fitToA4();window.print();return false;" align="absmiddle"
style="visibility:<%=style%>">
</body>
答案 0 :(得分:0)
如果您在window.print()
试试这个:
function Print(){
window.print();
setTimeout(function () {
window.close();
}, 10);
}
您可以在没有超时的情况下执行此操作,但是在没有Chrome的情况下会出现reference问题,并且添加超时似乎可以解决此问题。