开发者

How to get the object of Iframe at clientside(javascript) which placed inside Table in asp.net

开发者 https://www.devze.com 2023-04-12 18:42 出处:网络
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:

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消