Friday 21 June 2013

Create and Read cookie in SharePoint 2010.

Problem Description:

Create and Read cookie in SharePoint 2010.
Resolution:

<script type="text/javascript">

/* Create Cookie Function*/
    createCookie("CookieVarLocation",VarLocation);
/* Read Cookie Function*/
    var x =readCookie("CookieVarLocation");
   function createCookie(name,value)
   {
     var expires = "";
     document.cookie = name+"="+value+expires+"; path=/";
   }
   function readCookie(name)
  {      
    var nameEQ = name + "=";
     var ca = document.cookie.split(';');
     for(var i=0;i < ca.length;i++)
     {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
       return null;
    }
</script>
Feel free to revert in-case of any query...
Product Applies To:
·         SharePoint Server 2010
·         SharePoint Foundation 2010
·         SharePoint Server 2013

No comments:

Post a Comment