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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *