2013-07-03 35 views
2

我正在使用jQuery printElement以打印div的内容。JQuery printElement在Internet Explorer中打印整个页面

它在Safari,Chrome和Firefox上运行良好,但是当我尝试使用Internet Explorer(所有版本)时,它仅打印整个页面而不是div。这是为什么?我能做什么?

下面是用来打印的代码:

$('.print_button').each(function() { 
    $(this).click(function() { 
     $(this).closest('.details').find('.div_to_print').printElement({ 
      pageTitle: '...', 
      overrideElementCSS: [ 
       '<?php echo stylesheet_path("print.css"); ?>' 
      ] 
     }); 
    }); 
}); 

回答

1

您是否尝试过使用简单的CSS:

@media print { 
     .element-not-to-print { 
      display: none; 
     } 
} 

OR

@media print { 
     .element-not-to-print { 
      visibility: hidden; 
     } 
} 

支持媒体查询是IE9 +http://caniuse.com/css-mediaqueries

对于IE7和IE8使用检查this article。或者直接在您的项目中加入this JavaScript file并继续使用不会像jQuery那样杀死您的性能的旧媒体查询。