1

I need to pass JSON object in new window which is opened using window.open()

I have requirement to display stored data in database into new window. At the same time i need to pass a JSON object which is available in current open window to this new window.

Possible ways I had :

  1. Can save json in cookie before open new window, and read it in ngOnInit() then remove it from cookie.
  2. Can pass required data in URL, but i have large JSON object

Please guide if we can do this by any another approach.

Thank you.

3 Answers 3

1

You can use localStorage too instead of cookies. I don't think you have better options if you have to use window.open().

To keep each component functionality self-contained I would use a service to get the json based on the id.

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

Comments

1

I think you can use Window.postMessage. window.open will return a Window object that you can call postMessage on; in the new window, you'll want to listen for the "message" event on the global window object.

Note that IE8 and IE9 don't support it for windows, only (i)frames.

Comments

0

Instead of cookies or localstorage, how about you use the window object you get when open the window.

var opened_window = window.open('someurl_here');
opened_window.json_data = JSON.stringify(this.local_json_data);

In the child window, you can access the data as part of your window object.

//Inject your window into this component (@Inject('Window') window maybe)
this.new_json_data = JSON.parse(this.window.json_data);

I think this should work.

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.