最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript: Read out session id from cookie - Stack Overflow

programmeradmin7浏览0评论

for websockets I have to expose my sessionid from the cookie.

I have searched a bit and found that I should be able to access cookies by:

console.log(document.cookie);

unfortunatly this doesn't work or better document.cookie contains an empty string even chrome itself shows me the cookie also authentication works.

Can it be that chrome hides the cookie for javascript?

for websockets I have to expose my sessionid from the cookie.

I have searched a bit and found that I should be able to access cookies by:

console.log(document.cookie);

unfortunatly this doesn't work or better document.cookie contains an empty string even chrome itself shows me the cookie also authentication works.

Can it be that chrome hides the cookie for javascript?

Share Improve this question asked Aug 12, 2012 at 17:57 bodokaiserbodokaiser 15.8k27 gold badges100 silver badges143 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

That can happen if the server is configured to send the session cookie with the HttpOnly flag. This way the cookie bees invisible/inaccessible to client side scripting languages like JS.

To achieve your concrete functional requirement, either reconfigure the server to not do so, or look for alternate means, e.g. setting a custom cookie (without the HttpOnly flag, of course), or letting the server side view technology dynamically print the current session ID as a JS variable or as an attribute of some HTML element so that JS can access it by traversing the HTML DOM.

发布评论

评论列表(0)

  1. 暂无评论