자바스크립트 현재 주소(URL),쿼리스트링 가져오기
실행결과 : [ jsfiddle ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <script type="text/javascript"> // 현재 페이지 주소(URL)을 가져올 함수 생성 function pageUrl() { var sHref = location.href; document.getElementById('aDiv').innerHTML = sHref; } // 현재 페이지 주소(URL)에서 쿼리스트링을 가져올 함수 생성 function pageQuery() { // window 객체의 location.search 속성으로 쿼리스트링 가져오기 var sQuery = location.search; // 쿼리스트링이 있는지 조건문으로 체크 if ( sQuery ) { document.getElementById('aDiv').innerHTML = sQuery; } else { document.getElementById('aDiv').innerHTML = '현재 페이지 URL에 쿼리정보가 없습니다.'; } } </script> </head> <body> <div> <input type='button' value='주소확인' onclick='pageUrl()' /> <input type='button' value='쿼리정보' onclick='pageQuery()' /> </div> <div id='aDiv' style='margin-top:10px;'> </div> </body> </html> | cs |
사용된 속성 - ( 속성명 클릭시 상세 설명 확인 가능 )
location.href - 현재 페이지 URL 을 가져옵니다.. ( location 객체 프로퍼티 )
location.search - 현재 페이지 URL 쿼리정보를 가져옵니다. ( location 객체 프로퍼티 )
'개발' 카테고리의 다른 글
[javascript] 모바일웹에서 레이어를 띄우면 본창 스크롤 안되게 하는 방법 (0) | 2014.01.08 |
---|---|
[javascript] iscroll 샘플 (0) | 2014.01.08 |
[Java] 날짜 표현하기 SimpleDateFormat (0) | 2013.12.31 |
[.net] 글자수 만큼 자르기 (0) | 2013.12.31 |
[javascript] 라디오버튼(radio) (0) | 2013.12.30 |