Thursday, March 10, 2011

Query string in Javascript

The function that can be called out for processing queries:

  function getQuerystring(key, default_)


     if (default_==null) default_="";

      key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

     var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");

     var qs = regex.exec(window.location.href);

     if(qs == null)

        return default_;


        return qs[1];


The url to that page on which you are using the querys tring function should be like this ? id=hjidsyf3425392

to retrive the Id from query string here i am using it on page load event


   function show()


    var id =getQuerystring('id');


Thats it enjoy!!!!!

No comments:

Post a Comment