I have iframe inside the column of <asp:table>
. I want to get the object of an iframe in javascript. I tried like this in <body>
section:
<script type="text/javascript">
function resizeIframe()
{
var height = document.documentElement.clientHeight;
height -= document.getElementById('frame').offsetTop;
height -= 20;
document.getElementById('frame').style.height = height + "px";
};
document.getElementById('frame').onload = resizeIframe;
window.onresize = resizeIframe;
<开发者_JAVA百科/script>
But I'm getting error like "object expected or null".
Your document has probably not finished loading (so, #frame
does not exist yet). To fix this, make sure that the frame already exists by adding the code after the frame (or at the end of the document):
<iframe .../> ...
<script>
document.getElementById('frame').onload = resizeIframe;
window.onresize = resizeIframe;
</script>
精彩评论