jquery.printarea.js 834 B

1234567891011121314151617181920212223242526
  1. (function($) {
  2. var printAreaCount = 0;
  3. $.fn.printArea = function()
  4. {
  5. var ele = $(this);
  6. var idPrefix = "printArea_";
  7. removePrintArea( idPrefix + printAreaCount );
  8. printAreaCount++;
  9. var iframeId = idPrefix + printAreaCount;
  10. var iframeStyle = 'position:absolute;width:0px;height:0px;left:-730px;top:-730px;';
  11. iframe = document.createElement('IFRAME');
  12. $(iframe).attr({ style : iframeStyle,id    : iframeId});
  13. document.body.appendChild(iframe);
  14. var doc = iframe.contentWindow.document;
  15. doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div>');
  16. doc.close();
  17. var frameWindow = iframe.contentWindow;
  18. frameWindow.close();
  19. frameWindow.focus();
  20. frameWindow.print();
  21. }
  22. var removePrintArea = function(id){
  23. $( "iframe#" + id ).remove();
  24. };
  25. })(jQuery);