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.