Cross window js interaction between a popup and another window of the same domain

我怕爱的太早我们不能终老 提交于 2019-12-11 05:29:28

问题


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?


回答1:


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;


来源:https://stackoverflow.com/questions/1550600/cross-window-js-interaction-between-a-popup-and-another-window-of-the-same-domai

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!