Click to See Complete Forum and Search --> : IFRAME Question....
I have a page with an iFrame named myFrame. I can access the tag properties (like name) like this: window.frames[0].name . Ok, so how do I acces the text inside the iframe. I understand that its basically just another document object but I am lost as how to access it properties.
I have some text in a Div tag named myDiv, so how do I get access to its 'value' properties?
Jason
I think something like this might work. In your iFrame, give your div tag an id, then change the elements in bold to reflect your page. Let me know if it works.
var content = top.iframename.document.getElementById('yourdivid').innerHTML;
That should throw the content of yourdivid into the content variable.
Here is what I got after your post:
Parent Page-
alert(window.frames[0].document.getElementsByName('myDiv').innerHTML);
Page contained in IFRAME-
<div id="myDiv">
test
</div>
Alert Box-
undefined
Any ideas?
Jason
gil davis
02-05-2003, 08:12 AM
Originally posted by kj2w
Ok, so how do I acces the text inside the iframe.In IE you can use window.myFrame.document.body.innerText.I have some text in a Div tag named myDiv, so how do I get access to its 'value' properties?A DIV does not have a "value" property. A FORM element has a "value" property. Are you confused?
A couple of things...First off all, you changed my code. You changed getElementsById to getElementsByName...No wonder it didn't work. Also, don't do window.frames[0] to reference you iFrame. Give the iFrame a name of myiframe like this <iframe name="myiframe" ...> Then do this...
alert(top.myiframe.document.getElementsById('myDiv').innerHTML);
You were both right. Here is what I got to work:
From Pyro-
alert(window.frames[0].document.getElementById('myDiv').innerHTML);
where 'myFrame' contained-
<body>
<div id="myDiv">
test
</div>
</body>
From Gil Davis-
alert(window.myFrame.document.body.innerHTML);
where 'myFrame' contained-
<body>
test
</body>
Thanks again guys. :)
Jason