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

0

4 Answers 4

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).

Sign up to request clarification or add additional context in comments.

1 Comment

it workd fine on chrome but doesnt work on firefox, and i am afraid it wont work on mobile phones browsers
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.

Comments

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

1 Comment

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.
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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.