0

I have an application which open several windows (with javascript) in the same domain.

I would like to share some javascript objects between these windows (an object which contains some configurations for example).

Is it possible to do this in javascript and how to do this ?

Thanks.

3
  • 1
    sounds like a good candidate for localStorage Commented Jan 28, 2013 at 14:55
  • Before localStorage, there were cookies Commented Jan 28, 2013 at 15:03
  • Cookies length is limited, I don't think I can use cookies for my problem because I want to store objects Commented Jan 28, 2013 at 15:05

3 Answers 3

2

There are 2 possibilities: local storage and session storage

The session storage stores value for duration of the session, the value gets deleted when browser is closed and re-opened.

// Store value
sessionStorage.setItem('key', 'value');
//or
sessionStorage['key'] = value; 
// Retrieve value
alert(sessionStorage.getItem('key'));

The local storage stores value beyond the duration of the session, the value can be retrievedeven after closing and re-opening the browser.

// Store value
localStorage.setItem('key', 'value');
//or
localStorage['key'] = value; 

// Retrieve value 
alert(localStorage.getItem('key'));
Sign up to request clarification or add additional context in comments.

Comments

0

Use localStorage along with JSON to store your objects as strings:

Setting:

window.localStorage.setItem('yourKey', JSON.stringify(yourObject));

Getting:

var yourObject = JSON.parse(window.localStorage.getItem('yourKey'));

the localStorage data will be shared across all of your pages as long as they exist in the same domain.

Comments

0

If you used window.open() to create the second window, window.opener in the second window might give you access to the first window. See MDN.

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.