posted by 준치 2009. 11. 18. 10:00

 

<HTML>

<HEAD>

<script type='text/javascript'>

var contextNum = 0;
function contextClick(){
   
    if(contextNum == 0)
    {
        MasterID = 'ctl00_PlaceHolderMain_TransportForms_';
        document.getElementById(MasterID+'SendContext').value = "";
    }
   
    contextNum = 1;
   
}

</script>

</HEAD>

 

<BODY>

<input type='text' id='fo' name='fo' onfocus=contextClick()' />

</BODY>

</HTML>

textbox에 클릭하면 스크립트로 textbox에 aaa가 들어간다..

posted by 준치 2009. 6. 2. 14:30
function changeCSS(fname,name,value,expiredays)
 {
  debugger;
  var todayDate = new Date();
      todayDate.setDate( todayDate.getDate() + expiredays );
      document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
  
  var tg = document.getElementById('ctl00_GetCss');
  if(tg) { tg.href=('/_layouts/1042/STYLES/'+fname+'.css'); }
 }
function changeBG(fname,name,value,expiredays)
 {
  debugger;
  var todayDate = new Date();
      todayDate.setDate( todayDate.getDate() + expiredays );
      document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
  
  var tg = document.getElementById('ctl00_GetBG');
  if(tg) { tg.href=('/_layouts/1042/STYLES/'+fname+'.css'); }
 }

<!-- 기본 레이아웃 CSS -->
<link href="/_layouts/1042/styles/SKPSPortal_layout.css" rel="stylesheet" type="text/css" />
<!-- 색상타입 CSS -->
<link id="ctl00_GetCss" href="/_layouts/1042/styles/SKPSPortalOrg.css" rel="stylesheet" type="text/css" />
<!-- 배경타입 CSS -->
<link id="ctl00_GetBG" href="/_layouts/1042/styles/SKPSPortalbg1.css" rel="stylesheet" type="text/css" />
<!-- CSS 컨트롤 & 쿠키굽기/읽기-->
<script type="text/javascript" src="/_layouts/1042/styles/cssControl.js"></script>
posted by 준치 2009. 4. 1. 18:47

 url 검색 호출하는 방식
// 검색버튼 클릭으로 통합검색
function TCategorySearch(str)
{
//debugger;
    TotalParameters = str;
    CallFlag = "TCategorySearch";
   
    var nowAddress = decodeURI(DefaultURL);
    var SearchBox = document.all["CategoryTxt"].value;
   
    SearchBox = change(SearchBox);   
   
    httpRequest = getXMLHttpRequest();
    httpRequest.onreadystatechange = SearchSaveCall;
    httpRequest.open("GET",nowAddress + "?keyword=" + encodeURI(SearchBox),true);
    httpRequest.send(null);
}

변환되는거 예)
idx 문자 escape charCode encodeURI

0 A A 65 A

1 a a 97 a

2 ? %3F 63 ?

3 ㄱ %u3131 12593 %E3%84%B1

4 음 %uc74C 51020 %EC%9D%8C

<body>

<script>

 str = "Aa?ㄱ음";

 v = "<table border = 1>

 <tr>

  <td> idx </td>

  <td>문자</td>

  <td>escape </td>

  <td>charCode </td>

  <td>encodeURI</td>

 </tr>

 for(i = 0; i<str.length; i++){

  v+ = "<tr>;

  v+ = "<td>"+i+"</td><td>"+str.charAt(i)+"</td> <td>"+escape(str.charAt(i))+"</td><td>"+str.charcodeAt(i)+"</td><td>"+encodeURI(str.charAt(i))+"</td>;

  v+ = "</tr>";

 }

 v+ = "</table>";

 document.write(v);

</script>

다름방법

"%"를 붙이고

Unicode 판별하여 "u"를 붙이고

charCodeAt으로 escape번호를 구한후 toString(16)으로 16진수를 변환한 후 toUpperCase로

대문자 변환하여 인위적으로 escape문자를 만들어서

해결할 수 있음

<script>

 var str = "fdk?'jh8Aau";

 var esc = "";

 for(var i=0; i < str.length; i++){

  esc = "%"+(escape(str.charAt(i)).match(/%u/g)?"u":"")+str.charCodeAt(i).toString(16).toUpperCase();

  document.write("<br>" +i+"=========================="

    +"<br>원래문자 : "+str.charAt(i)

    +"<br>escape문자: "+esc

    +"<br>다시원래대로:"+unescape(esc));

 }

</script>


posted by 준치 2009. 2. 10. 22:27

var str = "http://yahoo.co.kr";

document.write(str.match(/http/));
document.write(str.replace(/http/,"timo")); 

document.write(str.match(/^t/));
 // ^ : t로 시작하는 문자열, str은 h 로 시작하므로 null 반환
document.write(str.replace(/^h/,"hahaha"));
// hahahattp://yahoo.co.kr 

document.write(str.match(/t$/));
// $ : t로 끝나는 문자열, str은 r 로 끝나므로 null 반환

document.write(str.replace(/r$/,"kakaka"));

// http://yahoo.co.kkakaka 
// . \n 을 제외한 한 문자
document.write(str.match(/.r/));
// . : 문자 + r 조합으로 이루어진 문자열 kr 반환
document.write(str.match(/h./));
// h + 문자 조합으로 이루어진 문자열 ht 반환
document.write(str.match(/h.t/)); 
// h + 문자 + t 조합으로 이루어진 문자열 htt 반환
str = "ooaaadddccadooaddd"
document.write(str.match(/d*d/g));
// * : d 앞에 d 가 0번 이상 나오는 문자열. ddd,d,ddd 반환
document.write(str.replace(/d*d/g,"__"));
//  ooaaa__cc__oo__ 
str = "xxxyyyxyz";
document.write(str.match(/xy?z/g));
// ? : z 앞의 문자 y 가 없거나 딱한번 있는 문자열 xyz 반환
document.write(str.replace(/xy?z/g,"_"));
// xxxyyy_  
str = "xxxyyyxyyyyyz";
document.write(str.match(/xy+z/g));
// + : z 앞의 문자 y 가 한번 이상 있는 문자열 xyyyyyz  반환
document.write(str.replace(/xy+z/g,"_"));
// xxxyyy_ 

[] : 괄호안의 !!문자!!나 !!숫자!!중 !!하나에!! 해당되면 참

document.write(str.match(/[xyz]/g));

// x,x,x,y,y,y,x,y,y,y,y,y,z


document.write(str.replace(/[xyz]/g,"_"));

// _____________

 

str = "ab12cd";

document.write(str.match(/ab[12]cd/g));

// [] 기호는 한개의 문자에 매치되므로 결과는 null

// ab1cd 이거나 ab2cd 인 문자열에 매치된다. 

str = "ab1cd";

document.write(str.match(/ab[12]cd/g));

// [] 기호는 한개의 문자에 매치되므로 결과는 ab1cd  

document.write(str.match(/ab[^12]cd/g));

// ab1cd 가 아니거나 ab2cd 가 아닌 문자열을 찾는다. 결과는 null 

document.write(str.match(/ab[^34]cd/g));

// ab3cd 가 아니거나 ab4cd 가 아닌 문자열을 찾는다. 결과는 ab1cd


{} 괄호앞의 !!문자!! 가 반복된 횟수를 의미 , 숫자만 들어갈 수 있다.


str = "xxxyyyz";

document.write(str.match(/x{3}y/g));

// x가 3번 반복된 문자열을 찾는다. 결과는 xxxy


document.write(str.match(/x{1,}y/g));

// x가 1번 이상 반복된 문자열을 찾는다. 결과는 xxxy


document.write(str.match(/x{0,3}y/g));

// x가 0번 이상 3번 이하 반복된 문자열을 찾는다. 결과는 xxxy,y,y


() 괄호안의 문자열을 참조 단독으로 쓰지 않고 *,+,? 등과 조합해서 사용된다.
str = "xyayayaz";

document.write(str.match(/x(ya)*z/g)); //==> xyayayaz  

str = "xxxxxabcabczzzzz";
document.write(str.match(/x(abc)*z/g));

// *는 z앞의 문자가 없거나 한번 이상 있는 경우를 나타내므로 결과는  xabcabcz


document.write(str.match(/x(abc)?z/g));

// ?는 z앞의 문자가 없거나 딱 한번 있는 경우를 나타내므로 결과는 null


document.write(str.match(/x(abc)+z/g));

// +는 z앞의 문자가 한번 이상 있는 경우를 나타내므로 결과는 xabcabcz
document.write(str.match(/x(abc){0,2}z/g));

// xabcabcz
document.write(str.match(/x(ab|cd){0,2}z/g));

// xabcabcz  

str = "http://naver.com http://na http://nav";
document.write(str.match(/(http:\/\/[a-zA-Z0-9\.]{1,})/g));

// http://naver.com,http://na,http://nav  

document.write(str.replace(/(http:\/\/[a-zA-Z0-9\.]{1,})/g,"*"));

// * * *
document.write(str.match(/(http:\/\/[a-zA-Z0-9\.]{10,})/g));

// null
[이메일]
-이메일 형식을 검색
/\w+@\w+\.\w+/g 

[숫자]
-숫자가 아닌 문자를 검색
/\D+/g 

[이름]
-이름에 숫자나 특수문자가 들어갔는지 검증
/[^a-zA-Z]+/g

/[^a-zA-Z가-하]+/g

정규식을 바로 테스트 해 볼수 있는 사이트

http://www.roblocher.com/technotes/regexp.aspx

http://blog.naver.com/liba2000?Redirect=Log&logNo=140052579331
posted by 준치 2009. 1. 20. 10:13

<script type="text/javascript">

function add(){
   var oText = document.createElement("input");
   oText.setAttribute("type", "text");
   oText.setAttribute("id", "txt");
   document.myform.appendChild(oText);
}
function del(){
   var oText = document.getElementById("txt");
   oText.parentNode.removeChild(oText);
}
</script>

posted by 준치 2008. 12. 4. 13:37
파이어 폭스에서 onload때 이벤트 먹게 하는거....

<script language="javascript" type="text/javascript">
    window.onload = function()
    {
       document.getElementById('id[1]').onchange = function()
       {
          window.location.href = 'product_info.php?products_id=<?php echo $_GET['products_id']; ?>&colour=' + this.options[this.selectedIndex].value;
       }
   }
</script>
posted by 준치 2008. 11. 8. 20:30
도메인이 다른 Iframe페이지를 찾다가 형이 보내준거...확인은 아직 안했음....

Cross Domain(크로스 도메인)
자바스크립트(Javascript) 보안 정책 중에 하나인 동일 근원 정책(Same-Origin Policy) 정책에 걸리는 부분이
 
바로 크로스 도메인을 할때 일어난다.
 
다시 말하면 서로 다른 도메인에서 자바스크립트로 접근하려 했을 때 혹은 다른 서버에 Ajax통신의 결과를 받을 때
 
보안상 접근을 거부한다.
 
 
자바스크립트는 같은 도메인 내에서만 작동하는 것을 원칙으로 한다. 이게 동일 근원 정책(Same-Origin Policy) 정책
 
다시 말해 샌드박스(SandBox) 정책이다. ( 웬지 모래가지고 놀면 그 안에서만 놀아야 혼나지 않을 것 같지 않나요?)
 
 
위의 주소에서 굵은 글씨가 도메인 영역이다.
 
자바스크립트는 자신을 로드한 도메인을 기준으로 자신의 도메인을 정한다.
 
그렇기 때문에 도메인이 다르면 자바스크립트 제어 통제권을 가질수가 없게 된다.
 
하지만 대형 사이트를 구축하다보면 이 문제를 극복해야 될 때가 있다.
 
이 부분에 대해서 알고 있는 팁들을 공유한다.
 
첫 번째 방법 서브 도메인이 동일한 부분이 있다면 이 방법을 추천한다.
 
 
 
이 두 주소를 보면 공통인 부분이 존재한다.
 
바로 이 부분을 이용해서 크로스 도메인을 해결 하려면
 
document.domain = "naver.com";
 
이렇게 스크립트에 넣어주면 된다.
 
단 subdomain 주소만 된다. 
 
두 번째 방법
JSONP(JSON with Padding)를 사용한다.
간단히 원리를 설명하면
우선 동적으로 script 태그를 생성하고 src부분에 호출할 서버 주소와 파라미터를 붙여서 넣고 document.body에 DOM메소드를 사용하여 append한다. 그렇게 하면 서버에 리퀘스트(요청)를 보내고 되고 서버는 리스판스(응답)를 하게 된다.
그리고 그 응답은 아래와 같은 문자열을 출력한다.
callback_function_name({name:"test"})
위와 같이 굵은 글씨가 바로 서버로 요청한 주소에 붙은 파라미터 값이다.
이것은 함수 이름으로 로드되면서 실행되게 한다. 이 함수가 넘겨받은 인자를 객체로 생성하고 지정된 콜백함수에 생성된 객체를 파라미터로 호출한다. 물론 마지막에는 붙인 script 태그는 제거한다. 
 
단 get 메소드 밖에 사용할 수가 없다. 주소로 요청을 보내기 때문이다.
이는 파라미터가 많으면 보낼수가 없다는 얘기이다.
 
세 번째 방법
Flash를 이용한다. 단 서버에 xml 설정 파일이 추가되어지고 클라이언트 단에서 flash파일이 필요하다.
Flash를 사용하면 get/post 모든 메소드 방법을 사용 할 수 있고 크로스 도메인 문제가 생기지 않는다.
하지만 말그대로 Flash를 사용해야 된다.
Flash가 동작하지 않은 환경에서는 동작을 하지 못한다.
 
이 외에도 여러가지 방법이 존재 할 수 있다.
 
하지만 가능한 동일한 도메인이 존재하는 환경에서는 document.domain이 좋은 해결책일 것이고
get으로만 보내도 괜찮은 환경이라면 JSONP를 추천한다.
 
어쨌거나 크로스 도메인은 더 이상 문제가 되지 않는다.
 
정 그래도 문제가 생긴다면 서버에게 일 좀 시키면 된다. ㅋㅋ

posted by 준치 2008. 11. 7. 21:55

:::내부:::
<script language="javascrip">
function 함수명()
{
소스
}
</script>


:::외부:::
<a href="#" onclick="alert('환영')">▶ 버튼에 스크립트 삽입
<a href="javascript:alert('환영')">▶ 버튼에 스크립트 삽입
<script language='javascript' src='fr.js'></script>▶ 외부에서 가져오기





:::Window객체:::
window.defaultStatus▶ 상태 표시줄에 표시할 문자열의 초기 값 설정
window.frames▶ 창에 포함된 프레임을 배열 형태로 지정
window.opener▶ 오픈메소드를 사용해서 새 상츨 열었을 경우, 새 창을 열도록 한 문서를 가리킴
window.parent▶ 상위 프레임을 가리킴
window.self▶ 현재 작업중인창
window.top▶ 프레임이 설정되기 전에 상태로 돌아감
window.classes▶ 문서 안에 정의된 모든 스타일시트의 정보를 갖음
window.tags▶ 모든 태그의 정보를 나타냄
window.screenX▶ 창의 x좌표 반환
window.screenY▶ 창의 y좌표 반환
window.close▶ 창이 닿여 있는지 확인 후 true, false 반환
windwo.length▶ 창 안에 프레임 수 반환
----------윈도우 메소드-----------
window.alert("메시지")▶ 경고 창
window.prompt("메시지", "기본문구")▶ 입력 창 띄움
window.confirm("메시지")▶ 확인, 취소창 띄움
window.status="환영합니다."▶ 상태표시줄 표시
window.close()▶ 창닫기
window.moveBy(x,y)▶ 브라우저를 상태좌표로 지정한 픽셀만큼 이동
window.moveTo(x,y)▶ 브라우저를 절대좌표로 지정한 픽셀만큼 이동
window.resizeBy(x,y)▶ 브라우저의 크기를 상대적으로 지정한 픽셀만큼 설정
window.resizeTo(x,y)▶ 브라우저의 크기를 절대 값으로 지정한 픽셀만큼 설정
window.scroll(x,y)▶ 창이나 프레임 안의 내용을 스크롤함
window.scrollBy(x,y)▶ 스크롤을 상대좌표로 이동
window.scrollTo(x,y)▶ 스크롤을 절대좌표로 이동
window.setTimeout("명령문",시간간격)▶ 일정한 시간 간격으로 명령문을 반복 실행(1/1000초 단위)
window.clearTimout()▶ SetTimeout()으로 동작되는 타이머 해제
window.print()▶ 현재 문서 출력
window.back()▶ 한단계 이전 URL로 이동
window.forward()▶ 한단계 이후 URL로 이동
window.home()▶ 브라우저에서 home으로 지정된 URL로 이동
window.stop()▶ 불러오기 중지
window.find("문자열")▶ 지정된 문자열이 있는지 검사(true, false 값)
window.open("경로","창이름","속성")▶ 새 창을 연다.
---------window.open()속성-----------
directories=yes/no▶ 연결 등 디렉토리 메뉴 표시 여부
menubar=yes/no▶ 메뉴 바 표시 여부
toolbar=yes/no▶ 툴 바 표시 여부
location=yes/no▶ 주소 입력줄 표시 여부
resizeble=yes/no▶ 크기 재설정 버튼 표시 여부
status=yes/no▶ 상태 표시줄 표시 여부
scrollbars=yes/no▶ 스크롤 바 표시 여부
copyhistory=yes/no▶ 히스토리 정보를 지정할지 여부
channelmode▶ 전체화면 모드
fullscreen▶ 전체화면으로 표시
width=값▶ 창 넓이
height=값▶ 창 높이
left=값▶ 좌측 좌표 값
top=값▶ 위쪽 좌표 값



:::특수문자:::
\n▶ 한줄 바꾸기
\t▶ 탭 키(커서가 탭  키를 누른 만큼 이동)
\b▶ 백 키(한 글자 좌측으로 이동하면서 좌측의 문자를 지움)
\f▶ 폼피트(한 장 넘어가 출력)
\r▶ 캐리지 리터(커서를 그 줄의 처음으로 이동)
\\▶ 역슬래시 표시
\'▶ 작은따옴표
\"▶ 쌍따옴표



:::이벤트핸들러:::
onClick▶ 창, 버튼 클릭
onDbclick▶ 더블클릭
onMouseover▶ 그림위로 마우스가 올라갈때
onMouseout▶ 마우스가 나갈때
onMousedown▶ 마우스 누르는 순간
onMousemove▶ 마우가 위치를 옮길때
onDragDrop▶ 클릭한 상태에서 이동 했을 때
onFocus▶ 커서가 위치할 때
onBlur▶ 커서를 잃어버렸을 때
onKeydown▶ 키보드 누를 때
onKeypress▶ 키보드를 누르는 순간
onKeyup▶ 키를 눌렀다가 떼는 순간
onSubmit▶ 전송 버튼을 눌러 폼 문서를 제출할 때
onReset▶ 입력 양식ㅇ르 초기화했을 때
onSelect▶ 입력 상자의 문자열을 선택하거나 체크상자, 라디오 버튼을 선택할때
onChange▶ 입력 양삭의 값이 바뀌었을 때
onLoad▶ 문서를 읽었을 때
onUnload▶ 문서를 닫을 때
onMove▶ 브라우저를 이동했을 때
onResize▶ 크기를 변경했을 때
onAbort▶ 그림을 읽는 도중 중지했을 때
onError▶ 문서나 그림을 읽는 도중 중지했을 때



:::내장함수:::
alert("mesage")▶ 확인버튼이 있는 메시지 창
prompt("mesage","기본문구▶ 입력상자가 있는 메시지 창을 띄움
confirm("mesage")▶ 확인 취소 버튼이 있는 창을 띄움
eval()▶ 문자열을 수식으로 바꿈
isNaN()▶ 전달받은 값이 숫자인지 문자인지 판별하여 숫자가 아닌 경우 true 값을 반환
parseFloat()▶ 문자열을 부동소수점으로 바꿈
parseInt()▶ 문자열을 정수로 바꿈
escape()▶ ISO-Latin-1 문제 셋을 아스키 값으로 바꿈,  URL 표기형으로 변환
unescape()▶ 위와 반대
isFinite()▶ 전달받은 값이 유리수인지 판단하여 유리수인 경우 ture 값 반환
Number()▶ 객체를 수치로 변환
String()▶ 객체를 문자열로 변환



:::Screen객체:::
window.screen.availHeight▶ 작업 표시줄을 제외한 화면의 높이를 픽셀 값으로 표시
window.screen.availWidth▶ 작업 표시줄을 제외한 화면의 너비를 픽셀 값으로 표시
window.screen.availTop▶ 화면 표시 영역의 y 좌표 표시
window.screen.availLeft▶ 화면 표시 영역의 x 좌표 표시
window.screen.height▶ 화면의 높이를 픽셀 값으로 표시
window.screen.width▶ 화면의 너비를 픽셀 값으로 표시
colorDepth▶ 컴퓨터에서 사용하고 있는 컬러 수를 표시
pixelDepth▶ 화면의 컬러 해상도를 표시(네비케이서용)




:::Document객체:::
document.bgcolor▶ 배경색
document.fgcolor▶ 문서의 글자색, 선색
document.linkcolor▶ 링크 색
document.vlinkcolor▶ 방문한 링크 색
document.alinkcolor▶ 선택 중인 링크 색
document.lastModifed▶ 홈페이지가 마지막으로 갱신된 날짜 저장
document.location▶ 웹 문서의 URL 저장
document.URL▶ 뭔서의 URL 주소 값 반환
document.domain▶ 서버의 도메인 명을 지정하거나 반환
document.title▶ <title>태그 사이에 문서 제목을 제공
document.cookie▶ 쿠키 파일의 정보를 읽고 쓸 수 있음
document.image▶ 문서에 삽입된 그림을 배열로 제공
document.links▶ 문서에 포함된 모든 링크의 이름을 배열로 제공
document.forms▶ <from>태그 입력 순서대로 배열로 제공
document.anchors▶ 문서에 포함된 하이퍼링크의 이름을 배열로 제공
document.Applets▶ 문서에 포함된 배열들의 배열을 제공
document.Embeds▶ 문서에 포함된 플러그인을 배열로 제공
document.layers▶ 레이어의 배열 정고를 제공
document.clear()▶ 문서의 모든 내용을 지움
document.open()▶ 문서의 내용을 보여줌
document.close()▶ open()으로 보여준 문서를 닫음
document.write()▶ 태그를 포함하는 문자열을 출력
document.writeIn()▶ <pre>태그와 함깨 사용하면 행 마지막에서 자동 개행
*document 객체에서 사용되는 핸들러는
ondbclick, onkeydown, onkeypress, onkeyup, onmousedown, onmouseup이다

  


:::Link객체:::
document.links[인텍스번호].속성▶ 인덱스 번호번째 링크 속성
document.links.length▶ 문서에 삽입된 링크 개수
document.링크이름.속성▶ 링크의 네임이 링크이름인 링크의 속성
---------link객체 속성------------
length▶ 문서 내 링크 개수 알려줌
href▶ URL 전체 주소 알려줌
protocol▶ 프로토콜의 종류 알려줌
host▶ 링크에 설정된 URL 주소, 호스트명, 포트번호 알려줌
hostname▶ 도메인명이나 IP 주소를 알려줌
pathname▶ URL에서 경로 부분의 정보를 알려줌
port▶ :8080과 같은 포트번호를 알려줌
search▶ ? 이후의 문자열을 알려줌
hash▶ anchor 객체의 이름을 알려줌
target▶ target 속성으로 지정한 문서가 열리는 프레임 이름을 알려줌
text▶ 해당 링크를 가지고 있는 문자열을 알려줌
x▶ 문서에서 해당 링크의 x좌표를 알려줌
y▶ 문서에서 해당 링크의 y좌료를 알려줌




:::Anchor객체:::
document.anchors[인덱스 번호].속성▶ 인덱스 번호번째 책갈피 속성
document.anchors.length▶ 문서에 삽입된 책갈피의 개수
document.anchors[책갈피명]또는 document.all[책갈피명]▶ 책갈피명이 같은 책갈피 설정
-------ancher객체 속성-------
lenght▶ 문서에 삽입된 책갈피 개수를 알려줌
name▶ 책갈피명을 알려줌
text▶ 책갈피로 설정한 문자열을 알려줌
x▶ 앵커 x좌표 값을 알려줌
y▶ 앵커 y좌표 값을 알려줌



:::Navigator객체:::
navigator.appCodeNamea▶ 브라우저의 코드명을 알려줌
navigator.appName▶ 브라우저의 종류를 알려줌
navigator.appVersion▶ 브라우저의 버전을 알려줌
navigator.userAgent▶ 브라우저의 코드명, 버전, 운영체제와 같은 브라우저의 정보를 알려줌
navigator.platform▶ 시스템 코드를 알려줌
navigator.javaEnable()▶ 브라우저에서 자바스키립트를 지원하는지 알려줌
navigator.tainEnable()▶ 문서가 정상적으로 열렸는지 알려줌



:::History객체:::
window.histor.속성
history.속성.메소드
-------history 메소드-----
back()▶ 뒤로
forward()▶ 앞으로
go(n)▶ n단계만큼 이동
go(0)▶ 새로고침
go(-1)▶ 이전 페이지로
go(1)▶ 다음 페이지로



:::Location객체
windows.locatioin.속성
location.속성=값
location.메소드
--------location속성-----------
hash▶ #다음에 오는 문자열, 즉 앵커 이름을 표시
host▶ 호스트명과 포트번호 표시
hostname▶ 호스트명을 표시
href▶ 완전한 형태의 URL 주소
pathname▶ 문서의 경로 표시
port▶ 프로토콜 종류 표시
protocol▶ 프로토콜 종류 표시
search▶ 검색 엔진을 실행할 때 나타나는 ? 이후의 문자 표시
---------location메소드-------
reload()▶ 문서를 다시 읽어옴(새로고침)




:::String객체:::
"환영합니다.".bold().fontcolor("red")
----------string메소드-----------
big()▶ 글자크기 크게
small()▶ 글자크기 작게
fontsize(값)▶ 글자크기 설정
fontcolor("색상")▶ 색 지정
bold()▶ 진하게
fixed()▶ 글자크기 조정
italic()▶ 기울임
strike()▶ 취소선
sup()▶ 위첨자
sub()▶ 아래첨자



:::문자열 처리:::
"환영합니다.".indexOf("합")
"환영합니다.".subsrt(2,4)
---------문자열메소드-----------
indexOf("문자")▶ 문자의 위치 값을 왼쪽부터 계산하여 숫자로 표시
indexOf("문자",n)▶ 문자를 문자열의 n번째 문자부터 찾는다
lastindexOf("문자")▶ 문자의 위치를 오른쪽부터 계산하여 숫자로 표시
lastindexOf("문자",n)▶ 문자를 문자열 n번째 문자부터 찾는다
charAt(n)▶ n번째 위치한 문자를 찾아준다.
substring(n,m)▶ n번째 문자부터 m번째 문자까지 표시
slice(n,m)▶ 위와 동일, 음수 값은 오른쪽부터 순번으로 계산
substr(n,m)▶ n번째 문자부터 m개의 문자를 표시
split("구분문자")▶ 구분문자를 이용해서 문자열 객체를 분리
concat("문자열")▶ 문자열을 문자열 객체에 결합
toUpperCase()▶ 모두 대문자로 표시
toLowerCase()▶ 모두 소문자로 표시
eval()▶ 문자열을 수치로 표시
toString(n)▶ 수치를 n진수로 바꾸어 표시
match()▶ 지정한 문자와 동일한 패턴을 찾는다. 없으면 널 값을 반환한다.
search()▶ 문자열에서 지정한 문자 턴을 찾아 그 패턴의 오프셋 값을 반환
replace()▶ 지정한 문자를 찾아 지정한 다른 문자열로 바꾼다.
CharCodeAt(n)▶ n번째 문자를 ISO-Lation-1 코드 값으로 표시한다. 

[출처] Javascript 기본|작성자 젊은오빠

posted by 준치 2008. 11. 5. 15:59

찾다가 보니 여기 많네여...시간되면 정리해서 다시 올려야겠어여..

http://warkyman.tistory.com/168
posted by 준치 2008. 11. 5. 15:14

자바스크립트에서 스트링관련해서 자주 쓰이는 함수들을 정리해 놓은 포스트가 있어 소개합니다.
이정도면 유용하게 활용할수 있을것 같네요.


    1
 /*--------------------------------------------------------------------------------*\

    2  *  JavaScript framework, version 2.0

    3  *

    4  *  Date : 2006. 08. 15.

    5  *  Copyright 1998-2007 by Vricks Studio All right reserved.

    6  *  @author Jeff Yang routine@vricks.com

    7  *  자주 쓰이는 스트링 관련 prototype관련 정리

    8 \*--------------------------------------------------------------------------------*/

    9 

   10 /*--------------------------------------------------------------------------------*\

   11  *  String prototype

   12 \*--------------------------------------------------------------------------------*/

   13     //-----------------------------------------------------------------------------

   14     // 문자의 좌, 우 공백 제거

   15     // @return : String

   16     //-----------------------------------------------------------------------------

   17     String.prototype.trim = function() {

   18         return this.replace(/(^\s*)|(\s*$)/g, "");

   19     }

   20     //-----------------------------------------------------------------------------

   21     // 문자의 좌 공백 제거

   22     // @return : String

   23     //-----------------------------------------------------------------------------

   24     String.prototype.ltrim = function() {

   25         return this.replace(/(^\s*)/, "");

   26     }

   27     //-----------------------------------------------------------------------------

   28     // 문자의 우 공백 제거

   29     // @return : String

   30     //-----------------------------------------------------------------------------

   31     String.prototype.rtrim = function() {

   32         return this.replace(/(\s*$)/, "");   

   33     }

   34     //-----------------------------------------------------------------------------

   35     // 문자열의 byte 길이 반환

   36     // @return : int

   37     //-----------------------------------------------------------------------------

   38     String.prototype.byte = function() {

   39         var cnt = 0;

   40         for (var i = 0; i < this.length; i++) {

   41             if (this.charCodeAt(i) > 127)

   42                 cnt += 2;

   43             else

   44                 cnt++;

   45         }

   46         return cnt;

   47     }

   48     //-----------------------------------------------------------------------------

   49     // 정수형으로 변환

   50     // @return : String

   51     //-----------------------------------------------------------------------------

   52     String.prototype.int = function() {

   53         if(!isNaN(this)) {

   54             return parseInt(this);

   55         }

   56         else {

   57             return null;   

   58         }

   59     }

   60     //-----------------------------------------------------------------------------

   61     // 숫자만 가져 오기

   62     // @return : String

   63     //-----------------------------------------------------------------------------

   64     String.prototype.num = function() {

   65         return (this.trim().replace(/[^0-9]/g, ""));

   66     }

   67     //-----------------------------------------------------------------------------

   68     // 숫자에 3자리마다 , 를 찍어서 반환

   69     // @return : String

   70     //-----------------------------------------------------------------------------

   71     String.prototype.money = function() {

   72         var num = this.trim();

   73         while((/(-?[0-9]+)([0-9]{3})/).test(num)) {

   74             num = num.replace((/(-?[0-9]+)([0-9]{3})/), "$1,$2");

   75         }

   76         return num;

   77     }

   78     //-----------------------------------------------------------------------------

   79     // 숫자의 자리수(cnt)에 맞도록 반환

   80     // @return : String

   81     //-----------------------------------------------------------------------------

   82     String.prototype.digits = function(cnt) {

   83         var digit = "";

   84         if (this.length < cnt) {

   85             for(var i = 0; i < cnt - this.length; i++) {

   86                 digit += "0";

   87             }

   88         }

   89         return digit + this;

   90     }

   91     //-----------------------------------------------------------------------------

   92     // " -> &#34; ' -> &#39;로 바꾸어서 반환

   93     // @return : String

   94     //-----------------------------------------------------------------------------

   95     String.prototype.quota = function() {

   96         return this.replace(/"/g, "&#34;").replace(/'/g, "&#39;");

   97     }

   98     //-----------------------------------------------------------------------------

   99     // 파일 확장자만 가져오기

  100     // @return : String

  101     //-----------------------------------------------------------------------------

  102     String.prototype.ext = function() {

  103         return (this.indexOf(".") < 0) ? "" : this.substring(this.lastIndexOf(".") + 1, this.length);   

  104     }

  105     //-----------------------------------------------------------------------------

  106     // URL에서 파라메터 제거한 순수한 url 얻기

  107     // @return : String

  108     //-----------------------------------------------------------------------------   

  109     String.prototype.uri = function() {

  110         var arr = this.split("?");

  111         arr = arr[0].split("#");

  112         return arr[0];   

  113     }

  114 

  115 /*---------------------------------------------------------------------------------*\

  116  *  각종 체크 함수들

  117 \*---------------------------------------------------------------------------------*/

  118     //-----------------------------------------------------------------------------

  119     // 정규식에 쓰이는 특수문자를 찾아서 이스케이프 한다.

  120     // @return : String

  121     //-----------------------------------------------------------------------------

  122     String.prototype.meta = function() {

  123         var str = this;

  124         var result = ""

  125         for(var i = 0; i < str.length; i++) {

  126             if((/([\$\(\)\*\+\.\[\]\?\\\^\{\}\|]{1})/).test(str.charAt(i))) {

  127                 result += str.charAt(i).replace((/([\$\(\)\*\+\.\[\]\?\\\^\{\}\|]{1})/), "\\$1");

  128             }

  129             else {

  130                 result += str.charAt(i);

  131             }

  132         }

  133         return result;

  134     }

  135     //-----------------------------------------------------------------------------

  136     // 정규식에 쓰이는 특수문자를 찾아서 이스케이프 한다.

  137     // @return : String

  138     //-----------------------------------------------------------------------------

  139     String.prototype.remove = function(pattern) {

  140         return (pattern == null) ? this : eval("this.replace(/[" + pattern.meta() + "]/g, \"\")");

  141     }

  142     //-----------------------------------------------------------------------------

  143     // 최소 최대 길이인지 검증

  144     // str.isLength(min [,max])

  145     // @return : boolean

  146     //-----------------------------------------------------------------------------

  147     String.prototype.isLength = function() {

  148         var min = arguments[0];

  149         var max = arguments[1] ? arguments[1] : null;

  150         var success = true;

  151         if(this.length < min) {

  152             success = false;

  153         }

  154         if(max && this.length > max) {

  155             success = false;

  156         }

  157         return success;

  158     }

  159     //-----------------------------------------------------------------------------

  160     // 최소 최대 바이트인지 검증

  161     // str.isByteLength(min [,max])

  162     // @return : boolean

  163     //-----------------------------------------------------------------------------

  164     String.prototype.isByteLength = function() {

  165         var min = arguments[0];

  166         var max = arguments[1] ? arguments[1] : null;

  167         var success = true;

  168         if(this.byte() < min) {

  169             success = false;

  170         }

  171         if(max && this.byte() > max) {

  172             success = false;

  173         }

  174         return success;

  175     }

  176     //-----------------------------------------------------------------------------

  177     // 공백이나 널인지 확인

  178     // @return : boolean

  179     //-----------------------------------------------------------------------------

  180     String.prototype.isBlank = function() {

  181         var str = this.trim();

  182         for(var i = 0; i < str.length; i++) {

  183             if ((str.charAt(i) != "\t") && (str.charAt(i) != "\n") && (str.charAt(i)!="\r")) {

  184                 return false;

  185             }

  186         }

  187         return true;

  188     }

  189     //-----------------------------------------------------------------------------

  190     // 숫자로 구성되어 있는지 학인

  191     // arguments[0] : 허용할 문자셋

  192     // @return : boolean

  193     //-----------------------------------------------------------------------------

  194     String.prototype.isNum = function() {

  195         return (/^[0-9]+$/).test(this.remove(arguments[0])) ? true : false;

  196     }

  197     //-----------------------------------------------------------------------------

  198     // 영어만 허용 - arguments[0] : 추가 허용할 문자들

  199     // @return : boolean

  200     //-----------------------------------------------------------------------------

  201     String.prototype.isEng = function() {

  202         return (/^[a-zA-Z]+$/).test(this.remove(arguments[0])) ? true : false;

  203     }

  204     //-----------------------------------------------------------------------------

  205     // 숫자와 영어만 허용 - arguments[0] : 추가 허용할 문자들

  206     // @return : boolean

  207     //-----------------------------------------------------------------------------

  208     String.prototype.isEngNum = function() {

  209         return (/^[0-9a-zA-Z]+$/).test(this.remove(arguments[0])) ? true : false;

  210     }

  211     //-----------------------------------------------------------------------------

  212     // 숫자와 영어만 허용 - arguments[0] : 추가 허용할 문자들

  213     // @return : boolean

  214     //-----------------------------------------------------------------------------

  215     String.prototype.isNumEng = function() {

  216         return this.isEngNum(arguments[0]);

  217     }

  218     //-----------------------------------------------------------------------------

  219     // 아이디 체크 영어와 숫자만 체크 첫글자는 영어로 시작 - arguments[0] : 추가 허용할 문자들

  220     // @return : boolean

  221     //-----------------------------------------------------------------------------

  222     String.prototype.isUserid = function() {

  223         return (/^[a-zA-z]{1}[0-9a-zA-Z]+$/).test(this.remove(arguments[0])) ? true : false;

  224     }

  225     //-----------------------------------------------------------------------------

  226     // 한글 체크 - arguments[0] : 추가 허용할 문자들

  227     // @return : boolean

  228     //-----------------------------------------------------------------------------

  229     String.prototype.isKor = function() {

  230         return (/^[가-힣]+$/).test(this.remove(arguments[0])) ? true : false;

  231     }

  232     //-----------------------------------------------------------------------------

  233     // 주민번호 체크 - arguments[0] : 주민번호 구분자

  234     // XXXXXX-XXXXXXX

  235     // @return : boolean

  236     //-----------------------------------------------------------------------------

  237     String.prototype.isJumin = function() {

  238         var arg = arguments[0] ? arguments[0] : "";

  239         var jumin = eval("this.match(/[0-9]{2}[01]{1}[0-9]{1}[0123]{1}[0-9]{1}" + arg + "[1234]{1}[0-9]{6}$/)");

  240         if(jumin == null) {

  241             return false;

  242         }

  243         else {

  244             jumin = jumin.toString().num().toString();

  245         }

  246         // 생년월일 체크

  247         var birthYY = (parseInt(jumin.charAt(6)) == (1 ||2)) ? "19" : "20";

  248         birthYY += jumin.substr(0, 2);

  249         var birthMM = jumin.substr(2, 2) - 1;

  250         var birthDD = jumin.substr(4, 2);

  251         var birthDay = new Date(birthYY, birthMM, birthDD);

  252         if(birthDay.getYear() % 100 != jumin.substr(0,2) || birthDay.getMonth() != birthMM || birthDay.getDate() != birthDD) {

  253             return false;

  254         }       

  255         var sum = 0;

  256         var num = [2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5]

  257         var last = parseInt(jumin.charAt(12));

  258         for(var i = 0; i < 12; i++) {

  259             sum += parseInt(jumin.charAt(i)) * num[i];

  260         }

  261         return ((11 - sum % 11) % 10 == last) ? true : false;

  262     }

  263     //-----------------------------------------------------------------------------

  264     // 외국인 등록번호 체크 - arguments[0] : 등록번호 구분자

  265     // XXXXXX-XXXXXXX

  266     // @return : boolean

  267     //-----------------------------------------------------------------------------

  268     String.prototype.isForeign = function() {

  269         var arg = arguments[0] ? arguments[0] : "";

  270         var jumin = eval("this.match(/[0-9]{2}[01]{1}[0-9]{1}[0123]{1}[0-9]{1}" + arg + "[5678]{1}[0-9]{1}[02468]{1}[0-9]{2}[6789]{1}[0-9]{1}$/)");

  271         if(jumin == null) {

  272             return false;

  273         }

  274         else {

  275             jumin = jumin.toString().num().toString();

  276         }

  277         // 생년월일 체크

  278         var birthYY = (parseInt(jumin.charAt(6)) == (5 || 6)) ? "19" : "20";

  279         birthYY += jumin.substr(0, 2);

  280         var birthMM = jumin.substr(2, 2) - 1;

  281         var birthDD = jumin.substr(4, 2);

  282         var birthDay = new Date(birthYY, birthMM, birthDD);

  283         if(birthDay.getYear() % 100 != jumin.substr(0,2) || birthDay.getMonth() != birthMM || birthDay.getDate() != birthDD) {

  284             return false;

  285         }

  286         if((parseInt(jumin.charAt(7)) * 10 + parseInt(jumin.charAt(8))) % 2 != 0) {

  287             return false;

  288         }

  289         var sum = 0;

  290         var num = [2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5]

  291         var last = parseInt(jumin.charAt(12));

  292         for(var i = 0; i < 12; i++) {

  293             sum += parseInt(jumin.charAt(i)) * num[i];

  294         }

  295         return (((11 - sum % 11) % 10) + 2 == last) ? true : false;

  296     }   

  297     //-----------------------------------------------------------------------------

  298     // 사업자번호 체크 - arguments[0] : 등록번호 구분자

  299     // XX-XXX-XXXXX

  300     // @return : boolean

  301     //-----------------------------------------------------------------------------

  302     String.prototype.isBiznum = function() {

  303         var arg = arguments[0] ? arguments[0] : "";

  304         var biznum = eval("this.match(/[0-9]{3}" + arg + "[0-9]{2}" + arg + "[0-9]{5}$/)");

  305         if(biznum == null) {

  306             return false;

  307         }

  308         else {

  309             biznum = biznum.toString().num().toString();

  310         }

  311         var sum = parseInt(biznum.charAt(0));

  312         var num = [0, 3, 7, 1, 3, 7, 1, 3];

  313         for(var i = 1; i < 8; i++) sum += (parseInt(biznum.charAt(i)) * num[i]) % 10;

  314         sum += Math.floor(parseInt(parseInt(biznum.charAt(8))) * 5 / 10);

  315         sum += (parseInt(biznum.charAt(8)) * 5) % 10 + parseInt(biznum.charAt(9));

  316         return (sum % 10 == 0) ? true : false;

  317     }

  318     //-----------------------------------------------------------------------------

  319     // 법인 등록번호 체크 - arguments[0] : 등록번호 구분자

  320     // XXXXXX-XXXXXXX

  321     // @return : boolean

  322     //-----------------------------------------------------------------------------

  323     String.prototype.isCorpnum = function() {

  324         var arg = arguments[0] ? arguments[0] : "";

  325         var corpnum = eval("this.match(/[0-9]{6}" + arg + "[0-9]{7}$/)");

  326         if(corpnum == null) {

  327             return false;

  328         }

  329         else {

  330             corpnum = corpnum.toString().num().toString();

  331         }

  332         var sum = 0;

  333         var num = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]

  334         var last = parseInt(corpnum.charAt(12));

  335         for(var i = 0; i < 12; i++) {

  336             sum += parseInt(corpnum.charAt(i)) * num[i];

  337         }

  338         return ((10 - sum % 10) % 10 == last) ? true : false;

  339     }

  340     //-----------------------------------------------------------------------------

  341     // 이메일의 유효성을 체크

  342     // @return : boolean

  343     //-----------------------------------------------------------------------------

  344     String.prototype.isEmail = function() {

  345         return (/\w+([-+.]\w+)*@\w+([-.]\w+)*\.[a-zA-Z]{2,4}$/).test(this.trim());

  346     }

  347     //-----------------------------------------------------------------------------

  348     // 전화번호 체크 - arguments[0] : 전화번호 구분자

  349     // @return : boolean

  350     //-----------------------------------------------------------------------------

  351     String.prototype.isPhone = function() {

  352         var arg = arguments[0] ? arguments[0] : "";

  353         return eval("(/(02|0[3-9]{1}[0-9]{1})" + arg + "[1-9]{1}[0-9]{2,3}" + arg + "[0-9]{4}$/).test(this)");

  354     }

  355     //-----------------------------------------------------------------------------

  356     // 핸드폰번호 체크 - arguments[0] : 핸드폰 구분자

  357     // @return : boolean

  358     //-----------------------------------------------------------------------------

  359     String.prototype.isMobile = function() {

  360         var arg = arguments[0] ? arguments[0] : "";

  361         return eval("(/01[016789]" + arg + "[1-9]{1}[0-9]{2,3}" + arg + "[0-9]{4}$/).test(this)");

  362     }

출처 http://www.zzbb.kr/24