Welcome to WebmasterWorld Guest from 54.146.1.178

Forum Moderators: open

Message Too Old, No Replies

child window getelementbyid

     
10:12 am on Dec 13, 2009 (gmt 0)

New User

5+ Year Member

joined:Oct 31, 2008
posts:17
votes: 0


Probably a dumb question but my limited js skills have failed! Any help appreciated ...

An html page, the parent, creates a child page into which is loaded a new url using window.open() from the parent page. I now need to getelementbyid() of an id from the child page into a variable in the parents js code. Something like:

parent
------
window.open(url,childwindow);
settimeout(wait for child to load fully);
childidvalue=childwindow.document.getelementbyid("idinchild").innerhtml;
alert (childidvalue);

12:27 pm on Dec 13, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 3, 2005
posts:1585
votes: 0


var childHandle; // this needs to be global
...
childHandle = window.open(url,childwindow);
checkLoaded();
...
function checkLoaded() {
var el = childHandle.document.getElementById("idinchild"); // case matters
if ( el ) { alert( el.innerHTML ); }
else { settimeout( checkLoaded ... ); } // assume not loaded yet, try later
}

Note that url must be same domain as parent page, security limitation.

10:55 pm on Dec 13, 2009 (gmt 0)

New User

5+ Year Member

joined:Oct 31, 2008
posts:17
votes: 0


Thanks daveVk, appreciated.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members