Like php session, js/jquery session is there?
In PHP I can store 开发者_如何转开发values in a session I can get until it is destroyed / unset, Is this possible in jQuery or JS, too?
I need to store client side values to retrieve them in another page.
Use cookies or if you need to store lots of data and don't need compatibility with non-state-of-the-art browsers you could also use HTML5 localStorage.
There is nothing like a session variable directly available in javascript but there are definitely some alternatives to achieve this type of behavior. Two I can think of:
Javascript cookies
As demonstrated on this page you can create and retrieve cookies in javascript.
AJAX
You could use AJAX requests to set and retrieve your session variables from a php file. If you're not familiar with AJAX you can find some decent examples here for the classic javascript approach or in case of jQuery in the jQuery .ajax() docs. This method is probably more reliable because it doesn't depend on the client allowing cookies.
You can use JStorage plugin for this ,JStorage , jStorage makes use of HTML5 local storage where available and userData behavior in Internet Explorer older versions. Webkit SQLite is not supported.Current availability: jStorage supports all major browsers - Internet Explorer 6+, Firefox 2+, Safari 4+, Chrome 4+, Opera 10.50+ , (under 1kB when gzipped)!
精彩评论