JohnJohny
JohnJohny

Reputation: 65

To check for session variable on load of a page

On load of a page i need to check if a session variable exists or not from a Javascript. I tried the following code. But it gives an error saying session is undefined.

Json=// i have hardcoded value here
Session("hai") =  "";
Session.set("hai",json);


if (( typeof session.get("hai") == 'undefined' && ((session.get("hai") == null)||(session.get("hai") == "") ) ){

}

Upvotes: 0

Views: 1298

Answers (1)

sphair
sphair

Reputation: 1670

If you want to store something between page requests, you can use Local Storage, or Session Storage.

localStorage.hai = json; // persistent across multiple sessions
sessionStorage.hai = json; // persistent in current session

This has nothing to do with server side sessions, though. It is unclear what your requirements are, so not sure this is suitable solution for you.

Here is a link for more information about Session Storage: http://www.nczonline.net/blog/2009/07/21/introduction-to-sessionstorage/

Upvotes: 1

Related Questions