onload event in XHTML

T

Trevor L.

I have been trying to maintain my site as valid XHTML.

But I find this doesn't validate
<iframe class="c1" id="News" src=""
onload="autoResize('News','table1')"></iframe>
This is because the onload event is not defined for the iframe element

However, it works fine.

autoResize() is this function
function autoResize(id,tname)
{
var newheight =
document.getElementById(id).contentWindow.document.getElementById(tname).clientHeight
document.getElementById(id).style.height = (newheight + 10) + "px"
}

It sets the height of the iframe "News" to the height of "table1" which
exists in news.html.
news.html is loaded into "News" by this:
<button onclick="loadIframe('News','news.html')">Open/Close News of this
Site</button>

Is there an alternative which is valid XHTML?

PS
autoResize() is used elsewhere with different html files loaded into
different iframes. All such html files have a table named 'table1' which
contains the entire content.

Is there a way to obtain the element 'table1' without referring to it
explicitly?
This doesn't work:
document.getElementById(id).contentWindow.document.tables[0].clientHeight

I thought of getElementsByTagname but this is non-standard, isn't it?
 
M

Murray

You go into strange places, Trevor! 8)

You could put the call to the autoResize immediately before the IFrame's
</body> tag, e.g.,

<script type="text/javascript>autoResize(...)</script>
</body>
 
T

Trevor L.

Murray said:
You go into strange places, Trevor! 8)

You could put the call to the autoResize immediately before the
IFrame's </body> tag, e.g.,

<script type="text/javascript>autoResize(...)</script>
</body>

Thanks, Murray.
Yes, I do go in strange places.

I guess it is just the thrill of the chase (or whatever). Squeezing the last
drop of functionality out of the language(s).

I'll give that a go. Actually, I did think of that later. It seems my best
thinking happens overnight :))
 
T

Trevor L.

Murray said:
You go into strange places, Trevor! 8)

You could put the call to the autoResize immediately before the
IFrame's </body> tag, e.g.,
<script type="text/javascript>autoResize(...)</script>
</body>

Tried and failed.

The iframe has no content originally. It reads
<iframe class="c1" id="News" src=""
onload="autoResize('News','table1')"></iframe>

The contents is loaded by the function loadIframe
<button onclick="loadIframe('News','news.html')">Open/Close News of this
Site</button>

I removed
onload="autoResize('News','table1')"
from the iframe tag.

I added this to the end of news.html
<script type="text/javascript">
autoResize('News','table1')
</script>

It didn't work. That is, the frame did not resize.

Perhaps the iframe id 'News' is not known inside news.html
 
M

Murray

Perhaps the iframe id 'News' is not known inside news.html

I think this is the problem. Personally, I avoid such thrilling chases....
8)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top