English 中文(简体)
Session value in Javascript
原标题:

How to read and write session values in javascript

最佳回答

If you speak about server-side session values, there s no other way than to somehow communicate with the server (e.g. with an asynchronous callback where you would read/write them with some method).

For simulation of client-side session variables, you might want to have a look here ;)

问题回答

you can t write directly to a server side session var with javascript. Assuming you are not using Ajax here.

Session variables reside on the server and as I m sure you are aware, Javascript is client-side.

A bit more context could be useful in understanding what exactly you re trying to achieve. As the session is held on the server, the only way to "instantly" communicate with it would be using AJAX calls.

This being not such a common way of operating maybe explaining your situation may help in giving you alternative, more common ways of doing what you need.

HTTP session vars are controlled by the server, JavaScript runs client side, and as such cannot modify the vars directly. Meaning this isn t possible using only Javascript

Java is client side scripting language. The client s web-browser does not know anything about session!

All you can do is to use cookies to store values which can be accessed across web-pages.

You can t because session variables are actually saved to a file on the server only. The only thing your browser knows about the session is the session id, which is saved into a cookie.

This is the whole point with sessions. The variables are safe because no one on the outside can read them. If you want variables readable by the browser, consider using cookies instead.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签