function content_print(){
    
                var initBody = document.body.innerHTML;
                window.onbeforeprint = function(){
                    document.body.innerHTML = document.getElementById('선택될 div id').innerHTML;
                }
                window.onafterprint = function(){
                    document.body.innerHTML = initBody;
                }
                window.print();     
            }            
        </script>

===============================================================================================

<div id='content'>
    내용 content_1
</div>

<div id='content_2'>
   내용 content_2
</div>
<input type="button" value="print" onclick="javascript:content_print();">
================================================================================================

선택될 div id  이부분에 div id 를 삽입하면 된다.
print 버튼을 누르면 지정된 div 안의 내용이 프린트 된다.

웹상에서 다수의 입력항목이 있는 페이지에서 데이터를 입력하는 도중 실수로 [esc]나 [back space] 키를 누르면
History back으로 인식하여 새로 입력한 모든 정보가 날라갑니다.
그렇게 되고나면 복구도 불가능하고 오로지 다시 입력하는 수 밖에 없습니다.
사용자의 실수 방지 차원에서 가능한 잊지않고 넣으면 좋을 것 같습니다..


/*
 ******************************************
 * 2005-08-10
 * 박 이 수
 * esc와 back-space 클릭 방지
 ******************************************
 */
document.onkeydown=checkKey;

function checkKey(){
 //alert("You pressed a following key: "+window.event.keyCode);
 // ESC Key 누를 때 데이터 사라지는 것 방지
 if(window.event.keyCode == 27){
  window.event.returnValue = false;
  return;
 }

 // back-space 누를 때
 if(window.event.keyCode == 8){

  // TextEdit가 아니면 작동하지 않도록
  if(!window.event.srcElement.isTextEdit){
   window.event.returnValue = false;
   return;
  }else if(window.event.srcElement.readOnly || window.event.srcElement.disabled){
   // readOnly나 disabled인 경우 작동하지 않도록
   window.event.returnValue = false;
   return;
  }
 }
 
 event.returnValue = true;
}

 from   http://blog.paran.com/yisupark/5320870

<html파일>

<div id="print_content">

<table>

  <tr>

    <td>출력할 부분</td>

  </tr>

</table>

</div>

 

<a href="javascript:print_content('serviceaddress');"><img src="img/button2.gif" border="0" width="57" height="22" style="cursor:hand"/></a>                                   

 

[js파일]

/* 특정 부분을 출력할때 쓰임 */
function print_content(p_service){
 //alert("dfdf");
 window.open("/html/print_content.html","","directories=0,location=0,menubar=0,scrollbars=0,toolbar=0,width=500,height=500, left=5000, top=5000;");

// left와 top의 위치를 5000으로 해서 화면에는 안보이게 한다.
}

 

[print_content.html]

<html>
<head>
<link rel="stylesheet" type="text/css" href="/ktf/css/css.css">
</head>
<body onLoad="window.close();">
<form name="testform">
<input type="hidden" name="data" value>
</form>
<script language="javascript">
 {
  var print_all;
  (document.testform.data.value = window.opener.document.all.print_content.innerHTML);
  print_all = (document.testform.data.value);
  document.write (print_all);
  window.print();
 }
</script>
</body>
</html>

*********************************************************

출력버튼을 클릭하면 출력하는 화면이 뜨고 인쇄를 클릭하면

div태그에 쌓여진 부분만 출력하게 된다..

from.  http://blog.naver.com/flydrago?Redirect=Log&logNo=40005671910   김경용

'프로그래밍Tips' 카테고리의 다른 글

JAD, JADClipse 설치하기  (2) 2009.09.07
Tomcat DOC ROOT 변경 및 Deploy 방법  (0) 2009.03.23
솔라리스에서 ifconfig 설정하기  (0) 2008.09.29
1.자동 띄우기
팝업창에 삽입
<html>
<head>
<title></title>
<script language="javascript">
<!--
function pop(){
window.open("팝업창파일", "pop", "width=400,height=500,history=no,resizable=no,status=no,scrollbars=yes,menubar=no")
}
//-->
</script>
</head>
<body onload="javascript:pop()">
이벤트 팝업창을 띄우기
</body>
</html>  

2.프레임이 있는 팝업창 닫기
팝업창에 삽입
<html>
<head>
<title></title>
<script language="Javascript">
<!--
function frameclose() {
parent.close()
window.close()
self.close()
}
//-->
</script>
</head>
<body>
<a href="javascript:frameclose()">프레임셋 한방에 닫기</a>
</body>
</html>

3.팝업창 닫고 프레임이 없는 부모창에서 원하는 페이지로 이동하기
팝업창에 삽입
<html>
<head>
<title></title>
<script language="javascript">
<!--
function MovePage() {
window.opener.top.location.href="연결할파일"
window.close()
}
//-->
</script>
</head>
<body>
<a href="javascript:MovePage();">자세한내용보기</a>
</body>
</html>

4.팝업창 닫고 프레임이 있는 부모창에서 원하는 페이지로 이동하기
팝업창에 삽입하고 팝업창의 설정은 프레임셋 페이지에 해야함
오픈창이 아닐경우에는 window.top.프레임이름.location.href="연결할파일" 적용한다
<html>
<head>
<title></title>
<script language="javascript">
<!--
function MovePage() {
window.opener.top.프레임이름.location.href="연결할파일"
//팝업창이 아닌것우..
window.close()
}
//-->
</script>
</head>
<body>
<a href="javascript:MovePage();">자세한내용보기</a>
</body>
</html>

5.팝업창 자동으로 닫기
팝업창에 삽입
<html>
<head>
<title>Close Window Timer</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<script language="JavaScript">
<!--
function closeWin(thetime) {
setTimeout("window.close()", thetime); //1000 은 1초를 의미합니다.
}
//-->
</script>
</head>
<body onLoad="closeWin('5000')">
이창은 5초후 자동으로 창이 닫힘니다.<br>
</body>
</html>

1. 부모창에서

<SCRIPT LANGUAGE="JavaScript">
<!--
 function getCookie(name) {
 var Found = false
 var start, end
 var i = 0
 
 while(i <= document.cookie.length) {
 start = i
 end = start + name.length
 
 if(document.cookie.substring(start, end) == name) {
 Found = true
 break
 }
 i++
 }
 
 if(Found == true) {
 start = end + 1
 end = document.cookie.indexOf(";", start)
 if(end < start)
 end = document.cookie.length
 return document.cookie.substring(start, end)
 }
 return ""
 }

function win_open(t_url) { //v2.0
 var noticeCookie=getCookie("i_don_want"); //i_don_want: 쿠키이름
 if (noticeCookie != "no")
     window.open(t_url,'','width=570,height=880,left=0,top=0')
}
function win_open2(t_url) { //v2.0
  window.open(t_url,'','width=800,height=580,left=0,top=0,scrollbars=yes,resizable=yes')

}
//-->
</SCRIPT>

<body  onload="javascript:win_open('popup.html')">


2. popup 화일에서 ( 여기서는 popup.html )


<script language="JavaScript">
function setCookie( name, value, expiredays ) {
        var todayDate = new Date();
        todayDate.setDate( todayDate.getDate() + expiredays );
        document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}
 
function closeWin()  {
 if ( document.cnjform.notice.checked ){
  setCookie("i_don_want", "no" , 1); //i_don_want: 쿠키이름
  self.close();
 }
}
</script>


<form name="cnjform" style="margin:0px;padding:0px;">
<table border="0" width="567">
  <tr>
    <td width="567">
     <p align="right">
      <input type="checkbox" name="notice" onclick="closeWin();"><font size=2><b>하루에 한번만 보기</b></font>
     </p>
    <td>
   </tr>
  </table>
</form>



자바스크립트 한글 입력 비활성화 하기

<input type="text" style="ime-mode:disabled">

자바스크립트 한글 입력 시작

<input type=text style="ime-mode:active;" size=20>

 
Syntax

HTML : { ime-mode : sMode }

JavaScript : object.style.imeMode [ = sMode ]

 

* sMode ( active | inactive | disabled | auto )

active : 한글 모드으로 변환 이후에는 한글 모드

inactive : 영문모드로 복귀 후 이후에는 영문 모드

disabled : 영문모드만 가능

auto : 자동으로

 

Example

<INPUT TYPE="text" STYLE="ime-mode:active">

+ Recent posts