homepage Welcome to WebmasterWorld Guest from 184.73.87.85
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
child window getelementbyid
cav609




msg:4042244
 10:12 am on Dec 13, 2009 (gmt 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);

 

daveVk




msg:4042279
 12:27 pm on Dec 13, 2009 (gmt 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.

cav609




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

Thanks daveVk, appreciated.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved