채택완료

Get값을 스크립트로 받기

2017-09-18 (월) 15:35:02 2,076
사이트주소 뒤에붙는 get값을 스크립트로 받고싶습니다
Php코드말고 스크립트로 받는 방법이있을까여
|

답변 3개

채택된 답변
+20 포인트

참고하세요.

Copy
<script>//목적 cgi화일이 아닌 순수 htm화일로도 파라메터를 넘겨받아 적용할 수 있음.tmp=window.location; //호출된 현재창의 주소 ex) http://kr.yahoo.com/1.html?a=1&b=1;tmp=String(tmp).split('?'); //? 이후가 배열에 담김tmp=tmp[1].split('&');//변수를 각각을 배열로 담고//변수값 출력for(k in tmp) {tmp2=tmp[k].split('='); //키와 값분리eval("var "+tmp2[0]+"=tmp2[1]");// document.write(tmp2[0]+' '+tmp2[1]+'<br>');}</script>

2017-09-18 (월) 15:42:06

querystring 전체를 알고 싶은 경우에는,

window.location.search 에 기본적으로 저장되어 있습니다.

Copy
alert(window.location.search);
아래와 같이 해주세요.(예: http://test.co.kr/index.html?test=10)
<script>
alert(getParam('test'));
</script>

답변을 작성하려면 로그인이 필요합니다.