我希望用户通过打印机打印所选照片。如果用户取消它或完成打印,我希望窗口页面消失。
它在Chrome上正常运行但不是IE11。在IE11,只有窗口页面。打印没有运行。
$(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();
});
});