Reputation: 905
Is it possible to get the id of the previous parent window if you launched the child window with document.location.href="diffPage.htm?name="+string;
where string would change each time?
Basically I have the main window with an id=favouritesTab
, called main.html that goes to diffPage.htm when a function is invoked.
I have tried window.parent.document.getelementById()
such as
var favouritesScreen = window.parent.document.getElementById('favouritesTab');
if(favouritesScreen.style.display == 'inherit')
{
..so on
But it doesn't seem to work at all. Does anyone know if there is a solution to this?
Upvotes: 0
Views: 7085
Reputation: 348972
Provided that your page is hosted at the same domain, accessing a document in the original window is possible via the window.opener
property.
A full demo is here: http://jsfiddle.net/eAjqX/1/show/
window.opener.document.getElementById
still works.The code for this demo (jQuery is not necessary):
// 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");
Upvotes: 1