...

View Full Version : How to write html code from an iframe to the parent document?



blacib
02-07-2004, 09:38 PM
Hi!

How to write html code from an iframe into the parent document?
It shoul append some html code to the parent document.

Thanks for your answer!

Basscyst
02-07-2004, 10:08 PM
hello -

If I remember correctly . . .

Points to a form element:


parent.document.formName.textName.value="My String Here";


or
Points to a <div>


parent.document.divName.innerHTML="My String";


Basscyst

glenngv
02-09-2004, 03:54 AM
Originally posted by Basscyst

Points to a <div>


parent.document.divName.innerHTML="My String";


Basscyst

parent.document.getElementById('elementId')

blacib
02-09-2004, 09:35 AM
Originally posted by glenngv
parent.document.getElementById('elementId')

This is all good and fine, but i need to append (merge) to the parent document, html code that i get from the iframe.

Let say the parent document looks like this:



<html>
..................
<iframe src="http://mydomain.com/ad.php" height=0 width=0></iframe>
..................
</html>


In the iframe i get some html that i need to write to the parent document.

It seems to work the following: from the iframe:


parent.document.open();
parent.document.write("<table>...</table>");
parent.document.close();


The only problem is that this overwrites the parent document.
I need to append to the parent.document, not to overwrite it.

glenngv
02-09-2004, 09:38 AM
main page:
<div id="containerID"></div>

iframe:
parent.document.getElementById('containerID').innerHTML='<table>...</table>'

blacib
02-09-2004, 09:58 AM
Originally posted by glenngv
main page:
<div id="containerID"></div>

iframe:
parent.document.getElementById('containerID').innerHTML='<table>...</table>'

The problem is that i don't have acces to the main page!
I cant update the main page, because it is not my!

I have to do it somehow from the iframe

Kor
02-09-2004, 11:29 AM
You can refere the content of a tag, then...

parent.document.getElementsByTagName('table')[i].innerHTML

check which is the order of the table, from top to bottom, starting from 0.

For instance, if your table is first, from top to botom, i = 0

parent.document.getElementsByTagName('table')[0].innerHTML

blacib
02-09-2004, 08:51 PM
Originally posted by Kor
You can refere the content of a tag, then...

parent.document.getElementsByTagName('table')[i].innerHTML



The problem is that i don't have acces to the main page!
I cant update the main page, because it is not mine!

Is there getElementsByTagName('body') ??

glenngv
02-10-2004, 02:07 AM
Originally posted by blacib
The problem is that i don't have acces to the main page!
I cant update the main page, because it is not my!

I have to do it somehow from the iframe

Do you mean the main page is from another domain?
If it is, then you can't update it outside of its domain because of cross-domain restriction.

blacib
02-11-2004, 10:38 AM
Originally posted by glenngv
Do you mean the main page is from another domain?
If it is, then you can't update it outside of its domain because of cross-domain restriction.

Will this work because of cross-domain restriction?

index.html of a third party site
<script src="http://www.mydomain.com/td.js"></script>
<iframe src="http://www.mydomain.com/js.php" width=0 height=0></iframe>


js.php:
<script>
parent.hello();
</script>


td.js contains the hello() function.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum