Cross window js interaction between a popup and another window of the same domain
-
20-09-2019 - |
Question
I'm trying to open a popup from window a
at example.com. then close window a
and open another window b
at the same domain (example.com). Is it possible to access the DOM of window a
from window b
and how?
The popup is opened from window a
by
window.open('http://example.com/blah', 'somename', settings..),
Executing the same from window b
with a different url (shown below) works
window.open("http://example.com/blah2", "somename" ...)
This seems to suggest windows are accessed by window name. But I could not find any way to access to DOM of the popup with or without the window's name. How would I do this?
Solution
Try something like
var newWind = window.open('http://example.com/blah', 'somename',settings);
if (newWind.opener == null) {
newWind.opener = window;
}
// here you can access DOM of new window
var newDoc = newWind.document;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow