0

I want user to print selected photo by printer. And if user cancel it or finish print, I want the window page to be disappear.

It is correctly operating at Chrome but not IE11. At IE11, only the window page is made. printing is not operating.

$(document).ready(function(){
    $("#print").one('click', function(ev){
        $('#main').prepend('<center><button class="btn btn-primary btn-lg" id="print2">복사하기</button></center>')
        $('.post').prepend('<input type="checkbox" />');
        $("#print2").on('click', function(){
            var images ='';
            $('.post').each(function(){
                if($(this).children('input[type="checkbox"]').prop('checked')){
                images+='<li class="col-xs-6"><img src ="'+$(this).find('img').attr('src')+'"></li>';
                }
            });
            if(images){
                var myWindow=window.open('','printWindow','width=800,height=800');
                myWindow.document.write("<head>");
                myWindow.document.write($('head').html());
                myWindow.document.write("</head>");

                myWindow.document.write("<body>");
                myWindow.document.write(images);
                myWindow.document.write("</body>");

                setTimeout(function () {
                    myWindow.print();
                }, 500);
                myWindow.onfocus = function () {
                    setTimeout(function () {
                        myWindow.close();
                    }, 500);
                }
            }
            else alert('먼저 선택하세요.');
        });
        ev.preventDefault();
    });
});
halfer
  • 19,824
  • 17
  • 99
  • 186
박형렬
  • 377
  • 1
  • 9
  • 24

0 Answers0