window.print() div 를 이용한 부분인쇄
보통 print 함수 사용시 원하지 않는 부분이 출력되는데 div 를 이용하여 원하는 부분만 출력이 가능합니다.
<HTML>
<HEAD>
<STYLE>
DIV { position: relative; }
</STYLE>
<SCRIPT>
var div2print;
function printDiv (id) {
if (document.all && window.print) {
div2print = document.all[id];
window.onbeforeprint = hideDivs;
window.onafterprint = showDivs;
window.print();
}
else if (document.layers) {
div2print = document[id];
hideDivs();
window.print();
}
}
function hideDivs () {
if (document.all) {
var divs = document.all.tags('DIV');
for (var d = 0; d < divs.length; d++)
if (divs[d] != div2print)
divs[d].style.display = 'none';
}
else if (document.layers) {
for (var l = 0; l < document.layers.length; l++)
if (document.layers[l] != div2print)
document.layers[l].visibility = 'hide';
<HEAD>
<STYLE>
DIV { position: relative; }
</STYLE>
<SCRIPT>
var div2print;
function printDiv (id) {
if (document.all && window.print) {
div2print = document.all[id];
window.onbeforeprint = hideDivs;
window.onafterprint = showDivs;
window.print();
}
else if (document.layers) {
div2print = document[id];
hideDivs();
window.print();
}
}
function hideDivs () {
if (document.all) {
var divs = document.all.tags('DIV');
for (var d = 0; d < divs.length; d++)
if (divs[d] != div2print)
divs[d].style.display = 'none';
}
else if (document.layers) {
for (var l = 0; l < document.layers.length; l++)
if (document.layers[l] != div2print)
document.layers[l].visibility = 'hide';
}
}
function showDivs () {
var divs = document.all.tags('DIV');
for (var d = 0; d < divs.length; d++)
divs[d].style.display = 'block';
}
</SCRIPT>
</HEAD>
<BODY>
<DIV>
<p><font size="2"><b>아래 선택 상자에서 원하는 인쇄 영역을 선택한 다음 "특정 부분 인쇄" 버튼을 클릭하세요!</b></font></p>
<FORM>
<SELECT NAME="divSelect">
<OPTION value="d1">첫 번째 영역만 인쇄
<OPTION value="d2">두 번째 영역만 인쇄
<OPTION value="d3">세 번째 영역만 인쇄
</SELECT>
<INPUT TYPE="button"
ONCLICK="var s = this.form.divSelect;
var divID = s.options[s.selectedIndex].value;
printDiv(divID);"
VALUE="특정 부분 인쇄"
>
</FORM>
</DIV>
<DIV ID="d1">
<b>[첫 번째 영역]</b><br>
첫 번째 영역입니다!<br><br>
</DIV>
<DIV ID="d2">
<b>[두 번째 영역]</b><br>
두 번째 영역입니다!<br>
두 번째 영역을 선택하여 인쇄해 보세요!<br><br>
</DIV>
<DIV ID="d3">
<b>[세 번째 영역]</b><br>
세 번째 영역입니다!<br>
세 번째 영역을 선택하여 인쇄해 보세요!<br>
}
function showDivs () {
var divs = document.all.tags('DIV');
for (var d = 0; d < divs.length; d++)
divs[d].style.display = 'block';
}
</SCRIPT>
</HEAD>
<BODY>
<DIV>
<p><font size="2"><b>아래 선택 상자에서 원하는 인쇄 영역을 선택한 다음 "특정 부분 인쇄" 버튼을 클릭하세요!</b></font></p>
<FORM>
<SELECT NAME="divSelect">
<OPTION value="d1">첫 번째 영역만 인쇄
<OPTION value="d2">두 번째 영역만 인쇄
<OPTION value="d3">세 번째 영역만 인쇄
</SELECT>
<INPUT TYPE="button"
ONCLICK="var s = this.form.divSelect;
var divID = s.options[s.selectedIndex].value;
printDiv(divID);"
VALUE="특정 부분 인쇄"
>
</FORM>
</DIV>
<DIV ID="d1">
<b>[첫 번째 영역]</b><br>
첫 번째 영역입니다!<br><br>
</DIV>
<DIV ID="d2">
<b>[두 번째 영역]</b><br>
두 번째 영역입니다!<br>
두 번째 영역을 선택하여 인쇄해 보세요!<br><br>
</DIV>
<DIV ID="d3">
<b>[세 번째 영역]</b><br>
세 번째 영역입니다!<br>
세 번째 영역을 선택하여 인쇄해 보세요!<br>
</DIV></BODY>
</HTML>
</HTML>
네이버 지식인 에서 발취 저작권 문제시 삭제 하겠습니다.
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
게시판 목록
퍼블리셔팁
퍼블리싱과 관련된 유용한 정보를 공유하세요.
질문은 상단의 QA에서 해주시기 바랍니다.
질문은 상단의 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 1217 | 반응형 | 3년 전 | 3104 | ||
| 1216 | 웹접근성 | 3년 전 | 2496 | ||
| 1215 | CSS | 4년 전 | 4903 | ||
| 1214 | 기타 | 4년 전 | 8361 | ||
| 1213 | CSS | 4년 전 | 3254 | ||
| 1212 | 웹접근성 | 4년 전 | 3642 | ||
| 1211 | CSS |
|
5년 전 | 4117 | |
| 1210 | 기타 | 5년 전 | 3345 | ||
| 1209 | CSS | 5년 전 | 3592 | ||
| 1208 | 기타 | 5년 전 | 3150 | ||
| 1207 | 기타 | 5년 전 | 2891 | ||
| 1206 | CSS |
moviepd
|
5년 전 | 3721 | |
| 1205 | HTML |
moviepd
|
5년 전 | 4384 | |
| 1204 | 기타 | 6년 전 | 7834 | ||
| 1203 | 웹접근성 | 6년 전 | 3013 | ||
| 1202 | 기타 | 6년 전 | 2986 | ||
| 1201 | 기타 | 6년 전 | 4325 | ||
| 1200 | 기타 | 6년 전 | 4122 | ||
| 1199 | 기타 | 6년 전 | 4135 | ||
| 1198 | 기타 | 6년 전 | 2616 | ||
| 1197 | 기타 | 6년 전 | 2686 | ||
| 1196 | 기타 | 6년 전 | 2470 | ||
| 1195 | 기타 | 6년 전 | 2460 | ||
| 1194 | 기타 | 6년 전 | 3049 | ||
| 1193 | 기타 | 6년 전 | 9237 | ||
| 1192 | 기타 | 6년 전 | 3886 | ||
| 1191 | 기타 | 6년 전 | 6225 | ||
| 1190 | 기타 | 6년 전 | 2443 | ||
| 1189 | 기타 | 6년 전 | 2346 | ||
| 1188 | 기타 | 6년 전 | 1825 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기