2013-07-03 57 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那樣殺死您的性能的舊媒體查詢。