Take the 2-minute tour ×

Is there a way in JavaScript to check if the browser session is new? I know in Java you can use Session.isNew(). Is there something equivalent in JavaScript?

share|improve this question
backend can always notify frontend, right? –  sv_in May 9 '11 at 15:55
add comment

3 Answers

up vote 3 down vote accepted

Session is a server-side concept. If the session cookie has been created, there is no way on the client-side to find out if session is new or not.

share|improve this answer
add comment

In more modern browsers you could use the sessionStorage object.

For example:

if (!sessionStorage.isNewSession)
    // Blah.

sessionStorage.isNewSession = true;

Details on the sessionStorage object:

It retains data as long as the current window is open. If the user refreshes the page, then it will have the same contents as before. If the user closes the browser and then opens your page again, then it will be empty.

But like I said: Modern browsers only.

As far as I know, compatibility is as follows:

Internet Explorer 8+ Firefox 3.5+ Safari 4+ Chrome 1+ Opera 10.6+

share|improve this answer
thank you! i have to support older browsers, but its a useful bit of information! –  benhsu May 11 '11 at 18:04
add comment

You can create some hidden fields in serverside and can check that value with javascript to check. Alternately you can use Cookies to achieve this with some workaround.

share|improve this answer
add comment

Your Answer


