【问题标题】:jQuery iframe file upload - trigger success or failjQuery iframe 文件上传 - 触发成功或失败
【发布时间】:2010-10-05 02:59:11
【问题描述】:

我有这个通过 iframe 上传选定文件的 javascript。我需要能够从 iframe 确定文件是否已成功上传。问题是上传文件可能需要 3 秒或 30 秒。当从 iframe 中完成上传时,我能想到的触发函数的最佳方法....如何从子 iframe 中定位主窗口?

                if (file === false) {
                    var newEl = that.reset(this);
                    //fix listener
                    triggerNotification('x', 'Unable to upload file, file type not accepted');
                } else {
                    var id = Math.floor(Math.random()*101);
                    var form = jQuery(this).hide().after("<div class='upload'><div class='file'>"+file+"</div><div class='status'><img src='/image/progress-bar.gif'/></div></div><iframe id='"+id+"' name='"+id+"' src='about:blank' width='0' height='0' style='display: block;'></iframe>").parents('form');
                    form.attr('target', id).submit();
                    console.log(jQuery('iframe', form));
                    console.log(jQuery('iframe', form).contents());
                    console.log(jQuery('iframe', form).contents().find('body'));
                    console.log(jQuery('iframe', form).contents().find('body').html());

                    jQuery('input[type="button"]', form.parents('.popup-panel')).show();

                    triggerNotification('check', 'File has been uploaded');

                    //form.replaceWith("<a href='/image/icons/accept.png' target='_blank'><img src='/image/icons/accept.png' style='max-width: 120px;'/></a><br/><span class='faded'>(Click to view actual size)</span>");
                }

【问题讨论】:

    标签: jquery file-upload


    【解决方案1】:

    解决方案是通过 iframe 触发页面上的 JS 函数,使用 parent.jQuery... 而不是 window.jQuery...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-07
      • 2014-01-15
      • 2012-02-09
      • 2011-12-16
      • 2012-04-20
      相关资源
      最近更新 更多