Setting session variable using javascript

Sam picture Sam · Aug 6, 2013 · Viewed 205k times · Source

I am getting name and email id of a user after he logs in via facebook to my website.. I want to add those variables in session on login form itself using javascript; I tried following:

FB.api('/me', function(me) {
        if (me.name) {
            document.getElementById('auth-displayname').innerHTML = me.name; <% Session["fbName"] = me.name; %>
        }
}

it gives error like me (in this line: <%Session["fbName"] = me.name; %>) does not exist in the current context etc.. my div "auth-displayname" is getting that value but I'm having problem with session variable

How can I do this

Answer

User picture User · Nov 19, 2013

You can use

sessionStorage.SessionName = "SessionData" ,

sessionStorage.getItem("SessionName") and

sessionStorage.setItem("SessionName","SessionData");

See the supported browsers on http://caniuse.com/namevalue-storage