javascript print() specific div without opening a

2019-03-05 09:14发布

问题:

I'm trying to print a specific div without opening a new window. I found this solution veru clever (from: How to print HTML content on click of a button, but not the page? )

function printDiv(selector) {
   $('body .site-container').css({display:'none'});
   var content = $(selector).clone();
   $('body .site-container').before(content);
   window.print();
   $(selector).first().remove();
   $('body .site-container').css({display:''});
}

works in FFox, but IE prints only a white page... what am I forgetting? PS I'm not an expert. If you suggest a solution, please supply the code. Thanks!