-4

Is it possible to write a page that open my site and show my cookie for the site? For example, open mysite.com and alert me my cookie at mysite.com.

Thanks in advance.

bouteillebleu
  • 2,456
  • 23
  • 32

2 Answers2

0

document.cookie in JavaScript contains all the cookies of the current document. So, you can easily alert that, or write it somewhere in your page. So, a simple answer could be:

window.onload = function(){
    var cookiesString = document.cookie;
    document.write("<div>" + cookieString + "</div>");
};
Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
  • yes it show me the Cookie , but i want open mysite.com and show the cookie of this page . – Jessica Watson Nov 21 '11 at 18:44
  • If you mean that from a.com you want to show cookies of b.com, then I gotta tell you that it's impossible. But if you want to show the cookies which are set for your website, then all those cookies which are related to the current path are delivered to you via `document.cookie` object by browser. :) – Saeed Neamati Nov 21 '11 at 18:47
  • no there is no 2 site , a page for e.x : saeed.html and when u open it show us our cookie of mysite.com – Jessica Watson Nov 21 '11 at 18:51
  • 1
    Then I don't understand what you mean. I think you should completely describe your problem, including the absolute URLs. For example, `http://site1.com/page1.html` and `http://site2.com/cookie.html` and so on. :) – Saeed Neamati Nov 21 '11 at 18:59
0
ar = document.cookie.replace(/;/g,"<br/>");
document.body.innerHTML += "<div style='background:white;position:fixed;top:0;'>"+unescape(ar)+"</div>";

you can add a "javascript:" and use it as a bookmark; add a new bookmark and set the location to :

javascript:var ar = document.cookie.replace(/;/g,"<br/>");document.body.innerHTML += "<div style='background:white;position:fixed;top:0;'>"+unescape(ar)+"</div>";
unloco
  • 6,928
  • 2
  • 47
  • 58