Categories
JavaScript Answers

How to pass a JavaScript variable to another browser window?

Spread the love

Sometimes, we want to pass a JavaScript variable to another browser window.

In this article, we’ll look at how to pass a JavaScript variable to another browser window.

How to pass a JavaScript variable to another browser window?

To pass a JavaScript variable to another browser window, we can add a property to the window handle object.

For instance, we write

const thisIsAnObject = { foo: "bar" };
const w = window.open("http://example.com");
w.myVariable = thisIsAnObject;

to call window.open to open a new window.

Then we add the myVariable property to the w window handle object.

Conclusion

To pass a JavaScript variable to another browser window, we can add a property to the window handle object.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.