jQuery | javascript | CSS

url 주소에서 매개변수 값 잘라내기

Godffs 2014. 9. 8. 00:24
반응형
URL 주소에서 매개변수 값을 잘라내는 예제 입니다.
(GET방식 매개변수 값 받아오기)

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title></title>

     <script type="text/javascript">

         function fn_load() {

             var str = returnUrlParams();

             alert(str);

         }

 

         function returnUrlParams() {

             var array = [], hash;

 

             //직접가져오기

             //var url = "http://goddfs?idx=233&name=goddfs";

             //var url_Address = url.slice(url.indexOf('?') + 1).split('&');

 

             //URL 에서 가져오기

             var url_Address = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

 

             for (var i = 0; i < url_Address.length; i++) {

                 hash = url_Address[i].split('=');

                 array.push(hash[1]);
                
//console.log(hash);

                 array[hash[0]] = hash[1];

             }

             return array;

         }

    </script>

</head>

<body>

     <form id="form1" runat="server" >

    <div>

        <input type="button" id="btnOK" onclick="fn_load();" value="버튼" />

        <input type="text" id="txt" />

    </div>

    </form>

 

</body>

</html>

결과화면입니다.




 

어때요? 참 쉽죠 ?
끝~

 

반응형