2

i have a one html page in which i am storing few user selected values now and want to use these values on another html page.

i am using jquery in my module and i have already tried window.name and window.localStorage but they don't persist values between two pages.

so please help me to solve this problem.

hunt
  • 283
  • 3
  • 4
  • 15
  • More duplicates: http://stackoverflow.com/search?q=javascript+persist – Pekka Mar 19 '10 at 13:54
  • all above link has the solution that don't work like as far as window.name and window.localStorage they really dont persist data between pages. – hunt Mar 19 '10 at 14:09

6 Answers6

3

If you don't want a cookies--and if you're directing from the first page to the second, how about passing the values as GET variables to the next page:

http://example.com/newpage.html?var1=blah?var2=blerg

then you can access that data with window.location.search.

carillonator
  • 4,715
  • 3
  • 29
  • 39
  • i can think over it but the restriction is to keep url clean – hunt Mar 19 '10 at 14:10
  • 2
    That is, frankly, a stupid restriction. – Quentin Mar 19 '10 at 14:36
  • Using the same principles, it might be "cleaner" to use the hash part of the url instead - this way it has no bearing on the server, and is purely client-side, eg `http://example.com/newpage.html#var1=blah&var2=blerg` Your javascript in the second page could then read this from `window.location.hash` and then if you wanted to keep the URL clean, you could remove the hash - as it is a hash this would not result in another roundtrip to the server, keeping everything local/client/browser-side – Graza Mar 19 '10 at 14:39
3

You could use the "hash":

http://my.app.com/page2.html#name1=val1&name2=val2

The hash would be ignored by the server, keeping things "clean". The second page can read the hash from

window.location.hash

and then parse out the name/value pairs with some simple string/regexp/array manipulation.

If you wanted the hash to be "hidden", your second page could also then remove the hash from the URL - this would not result in another trip to the server - changes to hash only result in browser/client side behaviour.

Graza
  • 5,010
  • 6
  • 32
  • 37
0

If it's just a few values, how about cookies?

Robusto
  • 31,447
  • 8
  • 56
  • 77
0

Store the value inside a cookie on the first page and and retrive it on the second. Its very easy with the Jquery Cookie plugin http://plugins.jquery.com/project/cookie

KTastrophy
  • 1,739
  • 15
  • 23
0

You would have to try and use cookies (assuming users are nice enough to enable those). Here is a very useful link: http://www.w3schools.com/JS/js_cookies.asp

superjos
  • 12,189
  • 6
  • 89
  • 134
ring bearer
  • 20,383
  • 7
  • 59
  • 72
-1

Finally i got pretty cool solution on

http://plugins.jquery.com/project/DOMCached

hunt
  • 283
  • 3
  • 4
  • 15