개발
[jQuery] 특정 DIV 프린트하기
세모리a
2013. 3. 28. 11:53
print_page.jsp
<%@ page language = "java" contentType = "text/html; charset=UTF-8"
pageEncoding = "UTF-8"%>
<! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
< html>
< head>
< meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8">
< title> 출력 </title >
< script type = "text/javascript" src = "/js/jquery-1.6.1.min.js" ></script >
< script type = "text/javascript">
<!--
$(document).ready( function (){
$( "#printHtml" ).html( $(opener.document).find("#${param.htmlId}" ).val());
window.print();
setTimeout ( function (){window.close();},1000);
});
// -->
</ script>
</ head>
< body>
< pre id = "printHtml">
</ pre>
</ body>
</ html>
호출페이지에 해당 DIV의 ID를 파라미터로 넘겨준다.
window.open("/print_page.jsp?htmlId=" + id);