Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how 2 change html code of document that is in frame?

Status
Not open for further replies.

baad

Programmer
Apr 10, 2001
1,481
RU
hi all!

what i mean is: can i change html code (usin inner/outerHTML or insertAdjacentHTML - i'm talkin about ie only) of file that is source of frame/iframe
 
only if the src is from the same domain, otherwise you get a security alert:

iframedoc = self.frames.iframename.document
el = iframe.doc.getElementById("elementid")
el.innerHTML = 'whatever <b>you</b> want&quot; jared@eae.net -
 
thunx jaredn, but i knew it. actually, i want 2 get html code from iframe & put it into the layer (div). but this code works only with *static* source.
my problem is:

when i change the frame's content (load another file) i cant get this new document's body - its empty, & so, all elements returned as *undefined*
(now i used this function with your code, thought it wuld help me... - nope : )

function doit(){
ifra=document.all.iframename
ifra.src='newfile.htm'
iframedoc = self.frames.iframename.document
el = iframedoc.all.body
alert(el+' '+el.innerHTML) //<---first time body.innerHTML is empty, but the second time - all works
//+el.innerHTML)
//getElementById(&quot;elementid&quot;)
//el.innerHTML = &quot;whatever <b>you</b> want&quot;
}

but
(if) when i call this function twice, it works: document object of this new file is not empty, & i can get whatewer i want, like u said

what shuld i do 2 get it 2 work from first time???

thunx for your time...
 
Hey! guys!

any ideas?

plz help me, i really need advice...
 
use something like:

function doIt(){
ifra=document.all.iframename
ifra.src='newfile.htm'
checkint = setInterval(checkIfReady,10)
}

function finishIt()
{
ifra=document.all.iframename
ifra.src='newfile.htm'
iframedoc = self.frames.iframename.document
el = iframedoc.all.body
alert(el+' '+el.innerHTML) //<---first time body.innerHTML is empty, but the second time - all works
//+el.innerHTML)
//getElementById(&quot;elementid&quot;)
//el.innerHTML = &quot;whatever <b>you</b> want&quot;

}

function checkIfReady()
{
var doc = self.frames.iframename.document;
if(doc)
{
if(doc.readyState=='complete')
{
clearInterval(checkint)
finishIt()
}
}
}
}

I didn't test any of it, but that should giv eu a starting point. jared@eae.net -
 
>>jaredn:

thunx, i'll try it
 
nope, doesnt work...

now i'm tryin 2 check for blabla.innerHTML!='' but it doesnt work either

 
Hi guys!
I think i did it! Well, if someone is interested, here is the code:

<script>
function doIt(fil){
ifra=document.all.iframename
ifra.src=fil
setTimeout('waitin()',0)
}

function waitin(){
if (frames.iframename.document.readyState == 'complete') { setTimeout('puting()',0) }
else setTimeout('waitin()',10)
}

function puting(){
var obj=self.frames.iframename.document.body
document.all.Layer2.innerHTML=obj.innerHTML
}
</script>


& there also must be iframe called iframename on the page and layer called Layer2


<div id=&quot;Layer1&quot; style=&quot;position:absolute; left:423px; top:71px; width:300px; height:27px; z-index:1; &quot;>
<form>
loadin file1<input type=button value='click here' onclick='javascript:doIt(&quot;file1.htm&quot;)' ><br>
loadin file2<input type=button value='click here' onclick='javascript:doIt(&quot;file2.htm&quot;)' >
</form>
</div>
<div id=&quot;Layer2&quot; style=&quot;position:absolute; left:12px; top:368px; width:661px; height:140px; z-index:2&quot;>
<center><strong><font color='red'>here the new content will appear (may be, on the 2nd time)</font></strong></center>
</div>
<iframe style=&quot;display:block&quot; name=iframename id=iframename src=&quot;&quot;></iframe>


style=&quot;display:block&quot; – just 2 see that content HAS been loaded; u can hide this iframe, and this eggzactly is what i was doin it for.(sorry for my english)

try it yourself, i got it to work on my computer, (win98, ie5.0) as for now i cant upload it on the NET, ‘coz my connection is xtrmly slow. Culd u guyz check it & tell me if it doesnt work on Inet?

And btw, culd anybody xplain me, why am i 2 use such construction setTimeout('puting()',0) – without it it doesnt want 2 work properly (& like i told before, without this stuff it works only from the second attempt)
 
hi guyz!
as u're here helpin pple now, wuld someone at last talk 2 me?

culd u shed some light on my situation? (see prev. post, question about timeout)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top