【问题标题】:Accessing Iframe content using jquery on IE在 IE 上使用 jquery 访问 iframe 内容
【发布时间】:2010-04-28 20:31:27
【问题描述】:

我正在尝试使用隐藏的 iframe 上传文件并获取响应。以下代码在 Firefox 上运行良好,但在 IE 上中断。它无法获得回复。

Line....
var content = $j(this).contents().find("body:last").text();

非常感谢任何帮助/建议。 谢谢。

$j('#uploadForm').submit(function(e) {

        var jThis = $j('#uploadForm');
        var strName = ("uploader" + (new Date()).getTime());
        var jFrame = $j("<iframe id=\"" + strName + "\" name=\"" + strName + "\" src=\"about:blank\" />");
        jFrame.css("display", "none");

        jThis
                .attr("method", "post")
                .attr("enctype", "multipart/form-data")
                .attr("encoding", "multipart/form-data")
                .attr("target", strName)
                ;

        $j("body:first").append(jFrame);

        jFrame.load(function(objEvent) {
            var content = $j(this).contents().find("body:last").text();
            alert(content);

    });
});

【问题讨论】:

    标签: jquery internet-explorer iframe file-upload


    【解决方案1】:

    我认为 JQuery 没有更具体的方法来抽象 IFRAME 实现中的差异。我也不确定是否可以在本身不引用 JQuery 的文档(您的 IFRAME)中的 DOM 元素上调用 JQuery 方法。所以,我会尝试这样的事情:

        var d = $j(this);
    if(d.body) {
        return d.body.innerHTML;
        }
    else if(d.innerHTML) {
        return d.innerHTML;
        }
    else {
        return 'Frame has no body';
        }
    

    【讨论】:

      【解决方案2】:

      试试这个:

      jFrame.load(function(objEvent) {
          var content = $(this.contentWindow.document.body).html();
          alert(content);
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多