弹出窗口与同一域的另一个窗口之间的跨窗口js交互

发布于 2024-08-07 14:34:04 字数 499 浏览 1 评论 0原文

我正在尝试从 example.com 的窗口 a 打开一个弹出窗口。然后关闭窗口 a 并在同一域 (example.com) 中打开另一个窗口 b。是否可以从窗口b访问窗口a的DOM以及如何访问?

打开弹出窗口,

window.open('http://example.com/blah', 'somename', settings..), 

通过使用不同的 url(如下所示)从窗口 b 执行相同的操作,可以从窗口 a

window.open("http://example.com/blah2", "somename" ...) 

这似乎表明窗口是通过窗口名称访问的。但我找不到任何方法来访问带有或不带有窗口名称的弹出窗口的 DOM。我该怎么做?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┼── 2024-08-14 14:34:04

尝试类似的东西

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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文