1

I have an HTML page and a java script file. When I click on a button in my html page I get a Json string in the java script file from the server. The Json string contains data that I want to use in other Html pages, so what would be a good technique to share the json string or object among the html pages, using java script only???

thx

4 Answers4

1

I don't know if that counts as "JavaScript only", but you could use DOM Storage.

window.localStorage.setItem('theData', theData)

That way it even survives closing the window (which you may or may not want).

Thilo
  • 257,207
  • 101
  • 511
  • 656
1

PersistJS is a wrapper around the new storage features in modern browsers (LocalStorage,globalStorage,openDatabase, gears,...). It uses feature detection to select the most appropriate storage solution. Including falling back to Cookies/Flash on older browsers.

http://pablotron.org/software/persist-js/

or more details on how it works at: http://pablotron.org/?cid=1557

eSniff
  • 5,713
  • 1
  • 27
  • 31
  • I assume we are talking about WAP 2.0? In which case I think it would work, but don't know for sure. I may play with this later, I do lots of mobile web myself and want to know now. – eSniff Nov 09 '11 at 16:01
1

You could use unique URI REST-style requests for Your data, together with cache headers, so Your browser could use it's native page caching.

Fedir RYKHTIK
  • 9,844
  • 6
  • 58
  • 68
0

Using JavaScript only you can go for cookies but they will be limited in size or you can go the new shiny HTML5 Local Storage if you only need to cater modern browsers.

EDIT: You have to open your HTML files through server if you use these, not directly by double clicking!

Community
  • 1
  • 1
DivinesLight
  • 2,398
  • 2
  • 24
  • 30