Jump to content

[SOLVED] access innerhtml property of div in a child window?


monkotronic

Recommended Posts

ok i opened a child window as such:

 

  theCart = window.open("whatever.html","theCart",cartFeatures);

 

now i want to assign a div (id= "theDiv") some innerhtml:

 

  theCart.document.getElementById('theDiv').innerHTML = theTable;

 

where theTable is some html code.  it doesn't work.  i get a "element has no properties" error.

 

any ideas?  websites?  tutorials?  code?  for me???  the question in a general sense is:  How do i reference the properties of an element in a child window?  explicit code would be helpful since i have tried many variations already. 

 

thanks.

Link to comment
Share on other sites

You gotta wait until the second page loads before you access it's elements. You can use the script inside the whatever.html page to get the code from the parent window once it loaded.

in whatever.html
<script language="javascript">
function ini_page(){
     document.getElementById('theDiv').innerHTML = opener.getConent();
}
</script>
<body onload="ini_page();">

in the main page
function getContent(){
     return theTable;
}

 

Just make sure theTable is a global variable.

 

Code untested.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.