0

I try to print with window.print(),It works in all browser fine except ie8 and ie9. I see solutions in Microsoft support site but because of security reason they are not useful for me. It works when i try ie8 or ie9 in compatible mode,but in real ie8 or ie9 it does not work. how can I fix it?

my code:

<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> 
m.nourzadeh
  • 1
  • 1
  • 2

1 Answers1

0

IE, and some versions of Chrome have been reported to have this issue if you do not explicitly close the window after window.print()

Try this:

function Print(){
    window.print();
    setTimeout(function () {
        window.close();
    }, 10); 
}

You could do it without the timeout but there have been reference to issues without Chrome, and the addition of the timeout seems to resolve it.

Albireo
  • 10,977
  • 13
  • 62
  • 96
davidcondrey
  • 34,416
  • 17
  • 114
  • 136