开发者

Accessing Iframe content using jquery on IE

I am trying to upload a file using an hidden Iframe and get the response back. The following code works fine on Firefox but breaks on IE. It fails on getting the response back.

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

Any help/suggestion is deeply appreciated. Thanks.

$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")
               开发者_StackOverflow .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);

    });
});


I don't think JQuery has a more specific method to abstract away the differences in IFRAME implementation. I'm also not sure if the JQuery methods can be called on DOM elements in a document (your IFRAME) that doesn't itself have a reference to JQuery. So, I'd try something like this:

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


Try this:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜