jQuery에서 실제 URL주소 파라미터 가져오기 방법
(인자값 추출)
예를들어 다음의 예시 웹주소가 있다고 하자.
http://testurl.com/main.html?name=test 라는 주소가 있을때
name에서 test뽑아내는 제이쿼리 코드 예시는 다음과 같다
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
var bdid = getUrlParameter('name');
댓글