Latest news
Home » javaScript » Get URL parameters using javascript or jquery

Get URL parameters using javascript or jquery

Example URL

http://smarttips.in?newsletter=1

<script>

var queryString = (function(url) {
if (url == “”) return {};
var smart = {};
for (var i = 0; i < url.length; ++i)
{
var pS=url[i].split(‘=’, 2);
if (pS.length == 1)
smart[pS[0]] = “”;
else
smart[pS[0]] = decodeURIComponent(pS[1].replace(/+/g, “””));
}
return pS;
})(window.location.search.substr(1).split(‘&’));

$(document).ready(function(){
if(queryString[“newsletter”]==1)
{
alert(‘Got it!!!’)
}
});

</script>

Leave a Reply

x

Check Also

How to Check Expired Sessions using jQuery Ajax and PHP

We can achieve using the php and ajax.The following ajax call execute in every 10 ...