아는 것이 좋은 것이다.

[jQuqery] request parameter 받기 본문

jQuery

[jQuqery] request parameter 받기

start0 2016. 4. 13. 15:19

<html>

<head>

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

    <title>테스트 파라미터 받기</title>

    <script src="http://code.jquery.com/jquery-latest.min.js"></script>

</head>

<body>



<p id="param">aaa</p>


<script>

    jQuery(function ($) {

        $.fn.getUrlParameter = function (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 type = $.fn.getUrlParameter('type');

        $("#param").text("type Value : " + type);

    });

</script>

</body>

</html>


# 설명

파라미터 type에 값을 넣어주면 스크립트로 값을 받을수 있음( 예 ->http://start0.tistory.com/test.html?type=값1111 )


# 실행 예시

type Value : 값1111

Comments