jquery: версия для печати
Javascript:
function printBlock() { $("input").each(function(){ $(this).attr("value", $(this).val()); }); $("select").each(function(){ var val=$(this).val(); $("option[value='"+val+"']", this).attr('selected', 'selected'); }); var PrintContent=$('#PrintContent').html(); $('body').addClass('printSelected'); var Logo='<div class="printLogo"><img src="/templates/images/logo.gif" alt=""/></div>'; var Contacts='<div class="printPhone"><b>Адрес</b><br/>Телефон</div><div style="clear:both;"></div>'; $('body').append('<div class="printSelection">'+Logo+Contacts+PrintContent+'</div>'); var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1; if (!is_chrome) { window.print(); window.setTimeout(pageCleaner,0); } else { document.onmousemove=window.print(); window.setTimeout(pageCleaner,1000); } return false; } function pageCleaner() { $('body').removeClass('printSelected'); $('.printSelection').remove(); }
CSS:
/*-------------------- PRINTER --------------------*/ .printLogo {float:left;} .printPhone {float:right;margin-right:10px;} .printPhone td{vertical-align:top;padding-right:25px;} .printSelected { background: #ffffff; padding: 10px; } .printSelected div { display:none; } .printSelected div.printSelection { display:block; } .printSelected div.printSelection div { display:block; } .printlink { float:right; } .printlink img{ cursor:pointer; }
HTML :
<div class="printlink" onclick='printBlock();'><img alt="Распечатать" src="/images/print.gif" /></div> <div id="PrintContent"> ... </div>