;(function ( $ ) { $.fn.printPreview = function( options ) { var elem = this; var opt = $.extend({ obj2print:'body', style:'', width:'670', height:screen.height-105, top:0, left:'center', resizable : 'yes', scrollbars:'yes', status:'no', title:'Print Preview' }, options ); if(opt.left == 'center'){ opt.left=(screen.width/2)-(opt.width/2); } $(opt.obj2print+" input").each(function(){ $(this).attr('value',$(this).val()); }); $(opt.obj2print+" textarea").each(function(){ $(this).html($(this).val()); }); return elem.bind("click.printPreview", function () { var btnCode = elem[0].outerHTML; var headString = ''; headString = $("head").html(); var str = ""+headString+opt.style+""; // str+=$(opt.obj2print)[0].outerHTML.replace(btnCode,'') // 기존 단일만 되서 수정함 $(opt.obj2print).each(function() { str+=this.outerHTML.replace(btnCode,''); }); str+=""; //top open multiple instances we have to name newWindow differently, so getting milliseconds var d = new Date(); var n = 'newWindow'+d.getMilliseconds(); var newWindow = window.open( "", n, "width="+opt.width+ ",top="+opt.top+ ",height="+opt.height+ ",left="+opt.left+ ",resizable="+opt.resizable+ ",scrollbars="+opt.scrollbars+ ",status="+opt.status ); newWindow.document.write(str); newWindow.document.title = opt.title; if( newWindow.addEventListener ) { newWindow.addEventListener('load', function() { newWindow.document.execCommand('print', false, null) || newWindow.print(); }, false); } else if( newWindow.attachEvent ) { newWindow.attachEvent('onload', function() { newWindow.document.execCommand('print', false, null) || newWindow.print(); }); } newWindow.document.close(); newWindow.focus(); }); }; }( jQuery ));