【发布时间】: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