developer747
developer747

Reputation: 15958

Pass json object from one HTML page to another

I am opening a page using window.open(). Is there a way to pass a JSON object from the parent to the child page? Ofcourse writing data to a cookie from the parent and reading that same cookie from the new page might be an option. Any simpler ways?

Upvotes: 2

Views: 5955

Answers (2)

Eugene Retunsky
Eugene Retunsky

Reputation: 13139

I see there are several ways to do this:

  1. Cookies. Write values to cookies and read it in the opened window.
  2. Pass as a part of url hash: window.open(url + '#' + encodeURIComponent(JSON.stringify(json));
  3. I would try to

    winRef = window.open(...);

    winRef.postMessage(...);

https://developer.mozilla.org/en/DOM/window.postMessage

I didn't try the third option, but it might be a nice alternative to 1 and 2.

Upvotes: 1

riso
riso

Reputation: 232

EDIT

var options = {foo:'foo'};
var myURL="http://localhost";
window.open( myURL + "/?options=" + JSON.stringify(options) );

didn't test that code before, try this, you can access it through GET

Upvotes: 1

Related Questions