27 January 2014

How to get querystring value in jquery

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript">
        function foo(key, default_) {
            if (default_ == null) default_ = "";
            var keyInLower = key.toLowerCase();
            var url = window.location.href;
            var urlInLower = url.toLowerCase();
            key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regex = new RegExp("[\\?&]" + keyInLower + "=([^&#]*)");
            var qs = regex.exec(urlInLower);
            if (qs == null)
                return default_;
            else
                return qs[1];
        }
        alert('ProductId: '+ foo('ProductId'));
        alert('CategoryId: '+ foo('CategoryId'));
    </script>
   

</head>
<body>
<form runat="server">


</form>
</body>
</html>

No comments:

Post a Comment