Showing posts with label query string. Show all posts
Showing posts with label query string. Show all posts

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_;

      else

        return qs[1];

   }

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

http://example.com ? id=hjidsyf3425392


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


  window.onload=show;



   function show()

   {

    var id =getQuerystring('id');

   }

Thats it enjoy!!!!!