|
-
Feb 13th, 2013, 12:36 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Setting a session variable in Javascript?
I'm wondering if it's possible to set a Session Variable in Javascript. I've been researching it and am finding mixed answers. Is there a way to do this and be able to reference that value in the code-behind?
Thanks,
-
Feb 13th, 2013, 08:26 AM
#2
Re: Setting a session variable in Javascript?
There is no direct way of setting a session variable using javascript. Sessions are maintained on the serever and js runs client side. You could probably use ajax to call server code to set a session variable or maybe you could just use a cookie.
-
Feb 13th, 2013, 11:42 AM
#3
Thread Starter
PowerPoster
Re: Setting a session variable in Javascript?
Thanks Mark, I appreciate your response!
-
Feb 13th, 2013, 06:00 PM
#4
Re: Setting a session variable in Javascript?
HTML5 has introduced Local Storage. If you need support in older browsers (< IE8), check for availability with Modernizr and use a polyfill if required.
http://www.w3.org/TR/webstorage/
http://dev.opera.com/articles/view/web-storage/
https://developer.mozilla.org/en-US/docs/DOM/Storage
The alternative would be to use Cookies as MarkT suggested, but they come with the overhead of being sent with every request/response and are transmitted in plaintext unless they are specifically set to send over SSL.
Last edited by tr333; Feb 13th, 2013 at 06:03 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|