Access saved cookie in browser

-1

Personal how do I access a cookie saved in the browser?

May be by mozila or by chrome

    
asked by anonymous 19.08.2018 / 15:34

1 answer

0
  • You can not see cookies from other sites.
  • You can not see http-only cookies.
  • All cookies that you can see are in the document.cookie property, which contains a semicolon-separated list of items in the default key = value.
  • For an implementation that covers the 3rd case you can do the following function:

    var getCookies = function(){
      var pairs = document.cookie.split(";");
      var cookies = {};
      for (var i=0; i<pairs.length; i++){
        var pair = pairs[i].split("=");
        cookies[(pair[0]+'').trim()] = unescape(pair[1]);
      }
      return cookies;
    }
    

    And use it as follows:

    var myCookies = getCookies();
    alert(myCookies.secret); // "do not tell you"
    

    Source: StackOverFlow

        
    19.08.2018 / 15:44