프론트엔드/JQuery
[JQuery] print() 화면 프린트 하기
an_apricot__
2021. 7. 5. 18:51
<style>
@media print {
#header, #footer, .no_print { display: none; }
}
</style>
// 프린트하지 않을 영역에 classname no_print 지정
function print() { //새창에서 프린트
var p = window.open(window.location.href, "_blank", "left=0, top=0, width=0, height=0");
var style = "<link rel='stylesheet' href='http://localhost:9000/space/css/room.css'>"
+ "<style> ul{list-style-type: none; padding: 0; display: inline-block;} ul span{box-sizing: border-box;}</style>";
p.document.write(style);
p.document.write($(".payment_wrap").html());
p.document.close();
p.focus();
p.print();
p.close();
}
function print() { //프린트 후 페이지 새로고침
var init = $("body").html();
window.onbeforeprint = function() {
var print_area = $("#print_area").html();
$("body").html(print_area);
$("body").css({"max-width":"800px", "min-width":"800px"});
};
window.onafterprint = function() {
location.reload();
};
window.print();
}