Henrik Stidsen said the following on 5/1/2006 8:41 AM:
I am trying to access a table in an iframe via javascript. It sounds
easy - but it wonīt work... And as they say "Then you must not be doing something right" :)
And yet, it works when the table is added directly to the parent
document and not in the iframe - so something must be right somewhere
:)
Well, something is still wrong and it is something else in your code
causing the problems.
It's irrelevant that it is added in ASP.NET, but, if you have ASP.NET
then why are you adding it to the document using client side scripting?
Just insert it with ASP.
Its an old script being updated for a new world - I wish I could, but I
canīt (as in, it takes too much work...)
I am not sure I buy into that one, but, ok.
I have tried both window.frames[], document.getElementById and even
document.getElementsByTagName, nothing has worked when the iframe is
involved... It takes a combination :)
Been there, done that - didnīt work either :(
It seems I cannot get af reference to the table in the iframe from the
parent document... ?? window.frames['IFrameName'].document.getElementById('TableID');
No luck...
Then something else in your code is breaking it.
If that doesn't work, post a URL to a sample page that shows the behavior.
Unfortunately not possible at the moment...
Why? Just a sample page. Or, sample code here.
I have a feeling that this ends with a lot of recoding...
It will, eventually, lead to recoding. It is not a matter of if, but when.
This script block:
<script type="text/javascript">
function newScriptElement(){
alert(window.frames['myIframe'].document.getElementById('myTable').innerHTML);
}
function addIFrame(){
document.getElementById('someContainer').innerHTML =
'<iframe src="blank2.html" name="myIframe"></iframe>';
}
</script>
With this HTML:
<button onclick="addIFrame()">Add IFrame</button>
<button onclick="newScriptElement()">Get Table</button>
<div id="someContainer"></div>
I added the IFrame using innerHTML and then got the table innerHTML from
blank2.html:
<table id="myTable">
<tbody>
<tr>
<td>My Table</td>
</tr>
</tbody>
</table>
That leads to the thought that something else in your page is screwing
it up.
--
Randy
comp.lang.javascript FAQ -
http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/