弹出窗口和同一域的另一个窗口之间的跨窗口JS交互 [英] Cross window js interaction between a popup and another window of the same domain
本文介绍了弹出窗口和同一域的另一个窗口之间的跨窗口JS交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从example.com的窗口a
打开一个弹出窗口.然后关闭窗口a
,然后在同一域(example.com)中打开另一个窗口b
.是否可以从窗口b
访问窗口a
的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?
弹出式窗口是通过
从窗口a
打开的
The popup is opened from window a
by
window.open('http://example.com/blah', 'somename', settings..),
从窗口b
使用不同的URL(如下所示)执行相同的操作
Executing the same from window b
with a different url (shown below) works
window.open("http://example.com/blah2", "somename" ...)
这似乎建议通过窗口名称访问窗口.但是,无论有没有窗口名称,我都无法找到访问弹出窗口DOM的任何方法.我该怎么办?
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?
推荐答案
尝试类似
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;
这篇关于弹出窗口和同一域的另一个窗口之间的跨窗口JS交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文