Solomon Sam
Solomon Sam

Reputation: 268

sending JSON string from one HTML page to another

I know this might sound silly and the easier alternative is to convert my pages to PHP. But is there a way to do this in HTML with Javascript or jQuery?

i want to sending JSON string from one HTML page to another.

in first.html there is a set of images that gets converted into a JSON string that looks like this:

{"images":[ {"src":"images/en1.png"},
    {"src":"images/en4.png"},
    {"src":"images/en2.png"},
    {"src":"images/fr4.png"},
    {"src":"images/b40.png"},
    {"src":"images/ca7.png"}
]}

i want to send this to second.html and in there a button called edit will take all this back to first.html

Is there a way to do this or is it impossible?

Upvotes: 0

Views: 1749

Answers (3)

kjanz1899
kjanz1899

Reputation: 47

You could take advantage of HTML5 offline storage using Andris Reinman's jStorage library. Just call the set method from your first.html page and the get method from your second.html page.

Upvotes: 1

yogi
yogi

Reputation: 19591

You could use querystring for that

something like

    <a 
href='second.htm?images={"images":[ {"src":"images/en1.png"},{"src":"images/en4.png"},{"src":"images/en2.png"},{"src":"images/fr4.png"},"src":"images/b40.png"},{"src":"images/ca7.png"}]}' >
    Go to second page
    </a>

and on second.htm you can get that value by using

window.location.href

Upvotes: 2

Suave Nti
Suave Nti

Reputation: 3747

You can use :

cookies to store the string and read the cookie in second html

passing the entire string(JSON stringify) as a URL parameter

Upvotes: 1

Related Questions