开发者

iframe load event not being triggered in jquery

the load event is not being triggered after i download a pdf as attach to the iframe. any ideas?

开发者_运维百科jQuery.download = function(url, data, method, callback){
    var inputs = '';
    var iframeX;
    var downloadInterval;
    if(url && data){
        // remove old iframe if has
        if($("#iframeX")) $("#iframeX").remove();
        // creater new iframe
        iframeX= $('<iframe src="[removed]false" name="iframeX" id="iframeX"></iframe>').appendTo('body').hide();


            iframeX.load(function(){
                callback();
            });



        //split params into form inputs
        $.each(data, function(p, val){
            inputs+='<input type="hidden" name="'+ p +'" value="'+ val + '" />';
        });

        //create form to send request
        $('<form action="'+ url +'" method="'+ (method||'post') + '" target="iframeX">'+inputs+'</form>').appendTo('body').submit().remove();
    };
}; 

MY ANSWER:

so this is the best hack so far i got to fix this, it uses the fact that the popup "save as" window makes the main window out of focus.

var onBlur=function(){
    $('#spinner').html("");
}

    if (/*@cc_on!@*/false) { // check for Internet Explorer
        document.onfocusout = onBlur;
    } else {
        window.onblur = onBlur;
    }


I don't see any PDF loading code in your example but my guess is that the PDF viewer running in the frame is no browser, so it doesn't support the standard HTML events.

Post another question asking what you need to achieve. Then we can maybe help.

[EDIT] What I mean: Where in all that is a HTML document loaded that could generate a HTML event? You put a PDF in the frame; PDFs don't generate HTML events.

But a solution might be to send two requests: First an AJAX request (runs in the background) and then POST the form. The server must keep the AJAX request pending until the PDF has been sent to the client and then, it should reply the AJAX request. That would give you an indication when the PDF has been transmitted. It's not perfect though.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜