View Full Version : iframe contentDocument
sir_yunus
02-12-2008, 03:03 PM
hi i have a problem like this
<iframe id="frame" src="contents.htm"></iframe>
in contents.htm I have an <div id="area">Our Content</div> and i want to reach div's inner html to change Our Content
in main page i write this code but it dosnt work
<script>
var x=null;
x=document.getElementById("frame");
alert(x.contentDocument.getElementById("area").innerHTML);
//i cant reach divs content please help:eek:
</script>
Hmm. Can we see more of your page? I tried this:
<script type="text/javascript">
function hidediv(){
document.getElementById("frame").contentDocument.getElementById("area").style.display = "none";
}
</script>
and it worked for me. Also, what does it alert? Null, Object, Undefined?
jscheuer1
02-13-2008, 02:12 AM
If you access the iframe as a part of the window.frames collection, like - say it was the first iframe on the page:
alert(window.frames[0].document.getElementById('area').innerHTML);
It's much simpler. When you access the iframe as an element on the page, the object that represents the content document actually varies from browser to browser.
sir_yunus
02-16-2008, 10:34 AM
Now i can rich iframe content with this code
var oIframe = document.getElementById('frame1');
var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
if (oDoc.document) oDoc = oDoc.document;
alert(oDoc.getElementById('frame1').id);//Show id in message box
but i cant use this code
oDoc.getElementById('area').focus ;
i cant focus so i cant change my text editor content
Note: i am making sitebuilder for university and user can edit his or her content and when he wants to prewiev i want to call iframe it looks like so simple but i cant please help if anyone has a simple editor not like FCKEditor ...
Thanks..
jscheuer1
02-16-2008, 04:47 PM
Top page:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function intoIframe(fr, el_id, txt){
window.frames[fr].document.getElementById(el_id).innerHTML=txt;
}
</script>
</head>
<body>
<iframe src="ed.htm" width="300" height="300" scrolling="auto" frameborder="1"></iframe><br>
<input type="button" onclick="intoIframe(0, 'ed1', 'Hello World');" value="Test">
</body>
</html>
ed.htm:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div id="ed1">
</div>
</body>
</html>
sir_yunus
02-16-2008, 08:23 PM
yes this code is well but ihave an another problem can you give your email me
mine is byron34master@gmail.com if you give or mail to me i can send my project and you will se my problem and may be you will help me
jscheuer1
02-16-2008, 08:55 PM
That other problem wouldn't happen to be that you are trying to populate a textarea rather than a div tag? If so, you need to access its value, not its innerHTML:
window.frames[fr].document.getElementById(el_id).value=txt;
My email is available if you click on my user name wherever it is a link on this forum. That will take you to my View Profile where there is information for contacting me. I would rather not actually publish my email address here for obvious reasons.
sir_yunus
03-06-2008, 08:20 PM
var frame1=document.getElementById('frame1');
var icerik=frame1.document.getElementById('area').id;
i write this code but i cant reach again i must use div not textarea because i am making sitebuilder
plz help
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.