【问题标题】:How do I refer to an <iframe>'s document using jQuery to get its height()?如何使用 jQuery 引用 <iframe> 的文档以获取其高度()?
【发布时间】:2009-10-13 18:56:39
【问题描述】:

我正在尝试获取

$('iframe').document.height();

$('iframe').contentWindow.document.height();

那些不起作用,而且我没有太多运气搜索。我将不胜感激!

【问题讨论】:

    标签: javascript jquery iframe document


    【解决方案1】:
    $("iframe",top.document).contents().height();
    alert("iframe height=" + $("iframe",top.document).height());
    

    【讨论】:

    • 谢谢克里斯,但这对我不起作用(至少在 Firefox 中)。我收到此异常:[异常...“无法转换 JavaScript 参数 arg 0”nsresult:“0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)”位置:“JS 框架 :: jqueryjs.googlecode.com/files/jquery-1.3.2.min.js ::匿名 :: 第 12 行”数据:否] 如果我将它分配给一个变量: var height = $("iframe", top.document).contents().height();它在赋值后仍然未定义并导致上述异常。
    • 另外,这个:$("iframe", top.document).height();似乎只是给了我
    【解决方案2】:

    试试这个:

    $(document).ready(function(){
    
        $("iframe").bind('mouseover', function(){
            alert($(this).contents().height());
        });
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-28
      • 1970-01-01
      • 2012-11-12
      • 2010-10-18
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 2010-11-11
      相关资源
      最近更新 更多