Sunday, 15 April 2012

jquery - open new window to print element -



jquery - open new window to print element -

try open new window include element print only. did not work in ie8.

function printelement(elementid) { var printwindow = window.open('', '_blank', 'status=0,toolbar=0,location=0,menubar=1,resizable=1,scrollbars=1'); printwindow.document.write("<html><head></head><body></body></html>"); var head = jquery('head').clone(); var printelement = jquery('#' + elementid).clone(); jquery(printwindow.document).find('head').replacewith(head); // not work in ie8 var body = jquery(printwindow.document).find('body'); body.empty(); body.append(printelement); // not work in ie8 homecoming false; }

thanks help.

how this? if understand you're wanting correctly, should work you. tested in ie 8.

working illustration on jsbin.

html:

<a href="#" id="one" class="trigger">print one</a> <a href="#" id="two" class="trigger">print two</a>

javascript:

var $trigger = $(".trigger"), printelement = function(id) { var printwindow = window.open('','_blank','status=0,toolbar=0,location=0,menubar=1,resizable=1,scrollbars=1'), html = $('html').clone(), printelement = $('#' + id).clone(), body; printwindow.document.write("<!doctype html><head></head><body></body></html>"); $(printwindow.document).find('html') .replacewith(html); body = $(printwindow.document).find('body') .html(printelement); }; $trigger.on("click", function(e) { var id = $(this).attr("id"); e.preventdefault(); printelement(id); });

jquery printing replace append

No comments:

Post a Comment