Access cookie saved in browser

Asked

Viewed 129 times

-1

Personal as I do to access a browser-saved cookie?

Can be by the api of mozzarella or by the api of Chrome

inserir a descrição da imagem aqui

1 answer

0

  1. You cannot see cookies from other websites.
  2. You cannot see http-only cookies.
  3. All cookies you can see are on the property document.cookie, containing a semicolon-separated list of items in the key pattern=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

  • Why no vote? Any feedback is welcome.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.