반응형
Javascript를 사용하여 인쇄 대화 상자를 팝업하려면 어떻게해야합니까?
사용자에게 프린터 친화적 인 페이지로 연결되는 "인쇄"링크가있는 페이지가 있습니다. 클라이언트는 사용자가 인쇄하기 쉬운 페이지에 도착하면 인쇄 대화 상자가 자동으로 나타나기를 원합니다. 자바 스크립트로 어떻게 할 수 있습니까?
window.print();
사용자 정의 팝업을 의미하지 않는 한.
넌 할 수있어
<body onload="window.print()">
...
</body>
나는 이것을 좋아하므로 원하는 필드를 추가하고 인쇄 할 수 있습니다.
function printPage() {
var w = window.open();
var headers = $("#headers").html();
var field= $("#field1").html();
var field2= $("#field2").html();
var html = "<!DOCTYPE HTML>";
html += '<html lang="en-us">';
html += '<head><style></style></head>';
html += "<body>";
//check to see if they are null so "undefined" doesnt print on the page. <br>s optional, just to give space
if(headers != null) html += headers + "<br/><br/>";
if(field != null) html += field + "<br/><br/>";
if(field2 != null) html += field2 + "<br/><br/>";
html += "</body>";
w.document.write(html);
w.window.print();
w.document.close();
};
나는 그들이 많은 프린터에서 많은 페이지에 필요한 가로 인쇄를 기억하도록하기 위해 이것을한다.
<a href="javascript:alert('Please be sure to set your printer to Landscape.');window.print();">Print Me...</a>
또는
<body onload="alert('Please be sure to set your printer to Landscape.');window.print();">
etc.
</body>
click 이벤트 핸들러가없는 링크 만있는 경우 :
<a href="javascript:window.print();">Print Page</a>
단추를 누르거나 페이지를로드 할 때 묶을 수 있습니다.
window.print();
문제가있는 경우 :
mywindow.print();
다른 사용하여 :
'<scr'+'ipt>print()</scr'+'ipt>'
완전한:
$('.print-ticket').click(function(){
var body = $('body').html();
var ticket_area = '<aside class="widget tickets">' + $('.widget.tickets').html() + '</aside>';
$('body').html(ticket_area);
var print_html = '<html lang="tr">' + $('html').html() + '<scr'+'ipt>print()</scr'+'ipt>' + '</html>';
$('body').html(body);
var mywindow = window.open('', 'my div', 'height=600,width=800');
mywindow.document.write(print_html);
mywindow.document.close(); // necessary for IE >= 10'</html>'
mywindow.focus(); // necessary for IE >= 10
//mywindow.print();
mywindow.close();
return true;
});
참고 URL : https://stackoverflow.com/questions/242182/how-can-i-pop-up-a-print-dialog-box-using-javascript
반응형
'programing tip' 카테고리의 다른 글
UNION [ALL]과 함께 SELECT INTO 절을 사용할 수 있습니까? (0) | 2020.06.20 |
---|---|
Visual Studio 2015 Broken Razor Intellisense (0) | 2020.06.20 |
write.csv 사용시 행 이름이 파일에 기록되지 않도록 방지 (0) | 2020.06.19 |
Chrome 웹 속성 네트워크 탭에서 확장 리소스를 숨길 수 있습니까? (0) | 2020.06.19 |
PostgreSQL에서 날짜 시간 필드의 날짜를 비교하는 방법은 무엇입니까? (0) | 2020.06.19 |