如果您使用document.location.href="diffPage.htm?name="+string;
启动子窗口,其中字符串每次都会更改,是否可以获取上一个父窗口的ID?
基本上我有一个带有id=favouritesTab
的主窗口,名为main.html,在调用函数时会转到diffPage.htm。
我尝试了window.parent.document.getelementById()
,例如
var favouritesScreen = window.parent.document.getElementById('favouritesTab');
if(favouritesScreen.style.display == 'inherit')
{
..so on
但它似乎根本不起作用。有谁知道是否有解决方案吗?
答案 0 :(得分:1)
如果您的网页托管在同一个域中,则通过window.opener
属性可能访问原始窗口中的文档。
这里有一个完整的演示:http://jsfiddle.net/eAjqX/1/show/
window.opener.document.getElementById
仍然有效。此演示的代码(jQuery不是必需的):
// New window page:
var i = 0;
document.onclick = function (){
try {
alert(window.opener.document.getElementById('test').value);
} catch (e) {
alert(e);
}
};
// Launcher
window.open("http://jsfiddle.net/eAjqX/show");