본문 바로가기
Snippets/Javascript

03. Javascript snippets - Url 파라미터 값 읽기

by 블리드카가 2017. 6. 5.
728x90

URL 파라미터 값 읽기

/**
 * URL의 파라메터 획득.
 * @param name
 * @returns
 */
function getParam(name){
      var result = "";
      var queryString = window.location.search;
      var paramMap = {}
      if (queryString == "") result = undefined;
      if (typeof result != "undefined"){
            var params = queryString.split("?")[1];
            
            if (params == "") result = undefined;
            
            if (typeof result != "undefined") {
                  var paramObj = params.split("&");
                  for (var i=0; i<paramObj.length; i++){
                        var datas = paramObj[i].split("=");
                        paramMap[datas[0]] = datas[1];
                  }
                  result = paramMap[name];
            }
      }
      
      return result;
}
728x90