GET으로 넘어온 파라미터 가져오기
자바스크립트에서 GET방식으로 넘어온 매개변수 값들을 서버의 처리 필요없이 사용하는법을 알려드리겠습니다;;
<Script language="JavaScript">
getParameter = function(name){
search=location.search;
if(!search){
//파라미터가 하나도 없을때
document.write("에러 출력 텍스트");
return false;
}
search=search.split("?");
data=search[1].split("=");
if(search[1].indexOf(name)==(-1) || data[0]!=name){
//해당하는 파라미터가 없을때.
return "";
return;
}
if(search[1].indexOf("&")==(-1)){
//한개의 파라미터일때.
data=search[1].split("=");
return data[1];
}else{
//여러개의 파라미터 일때.
data=search[1].split("&"); //엠퍼센트로 자름.
for(i=0;i<=data.length-1;i++){
l_data=data[i].split("=");
if(l_data[0]==name){
return l_data[1];
break;
}else continue;
}
}
}
</Script>
이런식으로 작성하시고 실제 호출할때는,
<Script>
getParameter("매개변수 이름");
</Script>
으로 입력해 주시면 되겠죠.
<Script language="JavaScript">
getParameter = function(name){
search=location.search;
if(!search){
//파라미터가 하나도 없을때
document.write("에러 출력 텍스트");
return false;
}
search=search.split("?");
data=search[1].split("=");
if(search[1].indexOf(name)==(-1) || data[0]!=name){
//해당하는 파라미터가 없을때.
return "";
return;
}
if(search[1].indexOf("&")==(-1)){
//한개의 파라미터일때.
data=search[1].split("=");
return data[1];
}else{
//여러개의 파라미터 일때.
data=search[1].split("&"); //엠퍼센트로 자름.
for(i=0;i<=data.length-1;i++){
l_data=data[i].split("=");
if(l_data[0]==name){
return l_data[1];
break;
}else continue;
}
}
}
</Script>
이런식으로 작성하시고 실제 호출할때는,
<Script>
getParameter("매개변수 이름");
</Script>
으로 입력해 주시면 되겠죠.
댓글 2개
쉽다zzz
12년 전
괜찮네요
senseme
12년 전
네...ㅎㅎ감사합니다.
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8030 | 9년 전 | 414 | ||
| 8029 | 9년 전 | 335 | ||
| 8028 | 9년 전 | 294 | ||
| 8027 | 9년 전 | 306 | ||
| 8026 | 9년 전 | 379 | ||
| 8025 | 9년 전 | 409 | ||
| 8024 | 9년 전 | 396 | ||
| 8023 | 9년 전 | 424 | ||
| 8022 | 9년 전 | 338 | ||
| 8021 | 9년 전 | 360 | ||
| 8020 | 9년 전 | 359 | ||
| 8019 | 9년 전 | 373 | ||
| 8018 | 9년 전 | 477 | ||
| 8017 | 9년 전 | 559 | ||
| 8016 | 9년 전 | 382 | ||
| 8015 | 9년 전 | 415 | ||
| 8014 | 9년 전 | 346 | ||
| 8013 | 9년 전 | 265 | ||
| 8012 | 9년 전 | 270 | ||
| 8011 | 9년 전 | 475 | ||
| 8010 | 9년 전 | 331 | ||
| 8009 | 9년 전 | 347 | ||
| 8008 | 9년 전 | 315 | ||
| 8007 | 9년 전 | 464 | ||
| 8006 | 9년 전 | 500 | ||
| 8005 |
|
9년 전 | 994 | |
| 8004 | 9년 전 | 384 | ||
| 8003 | 9년 전 | 453 | ||
| 8002 | 9년 전 | 347 | ||
| 8001 |
|
9년 전 | 688 | |
| 8000 | 9년 전 | 456 | ||
| 7999 | 9년 전 | 407 | ||
| 7998 | 9년 전 | 465 | ||
| 7997 | 9년 전 | 335 | ||
| 7996 | 9년 전 | 564 | ||
| 7995 | 9년 전 | 509 | ||
| 7994 | 9년 전 | 401 | ||
| 7993 | 9년 전 | 470 | ||
| 7992 | 9년 전 | 542 | ||
| 7991 | 9년 전 | 288 | ||
| 7990 | 9년 전 | 322 | ||
| 7989 | 9년 전 | 329 | ||
| 7988 | 9년 전 | 756 | ||
| 7987 | 9년 전 | 460 | ||
| 7986 | 9년 전 | 463 | ||
| 7985 | 9년 전 | 541 | ||
| 7984 | 9년 전 | 459 | ||
| 7983 | 9년 전 | 697 | ||
| 7982 | 9년 전 | 556 | ||
| 7981 | 9년 전 | 514 | ||
| 7980 | 9년 전 | 535 | ||
| 7979 | 9년 전 | 525 | ||
| 7978 | 9년 전 | 490 | ||
| 7977 | 9년 전 | 430 | ||
| 7976 | 9년 전 | 891 | ||
| 7975 | 9년 전 | 404 | ||
| 7974 | 9년 전 | 448 | ||
| 7973 | 9년 전 | 631 | ||
| 7972 | 9년 전 | 421 | ||
| 7971 | 9년 전 | 495 | ||
| 7970 | 9년 전 | 338 | ||
| 7969 | 9년 전 | 577 | ||
| 7968 | 9년 전 | 425 | ||
| 7967 | 9년 전 | 410 | ||
| 7966 | 9년 전 | 414 | ||
| 7965 |
|
9년 전 | 1045 | |
| 7964 | 9년 전 | 434 | ||
| 7963 | 9년 전 | 443 | ||
| 7962 | 9년 전 | 442 | ||
| 7961 |
전갈자리남자
|
9년 전 | 532 | |
| 7960 | 9년 전 | 1000 | ||
| 7959 | 9년 전 | 583 | ||
| 7958 | 9년 전 | 435 | ||
| 7957 | 9년 전 | 390 | ||
| 7956 | 9년 전 | 389 | ||
| 7955 | 9년 전 | 493 | ||
| 7954 | 9년 전 | 427 | ||
| 7953 | 9년 전 | 471 | ||
| 7952 | 9년 전 | 393 | ||
| 7951 | 9년 전 | 527 | ||
| 7950 | 9년 전 | 422 | ||
| 7949 | 9년 전 | 416 | ||
| 7948 | 9년 전 | 355 | ||
| 7947 | 9년 전 | 969 | ||
| 7946 | 9년 전 | 488 | ||
| 7945 | 9년 전 | 430 | ||
| 7944 | 9년 전 | 490 | ||
| 7943 | 9년 전 | 420 | ||
| 7942 | 9년 전 | 435 | ||
| 7941 | 9년 전 | 426 | ||
| 7940 | 9년 전 | 927 | ||
| 7939 | 9년 전 | 418 | ||
| 7938 | 9년 전 | 433 | ||
| 7937 | 9년 전 | 324 | ||
| 7936 | 9년 전 | 907 | ||
| 7935 | 9년 전 | 505 | ||
| 7934 | 9년 전 | 484 | ||
| 7933 | 9년 전 | 612 | ||
| 7932 | 9년 전 | 550 | ||
| 7931 | 9년 전 | 610 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기