我有这个javascript通过iframe上传所选文件。我需要能够从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>");
}
答案 0 :(得分:0)
解决方案是通过使用parent.jQuery...
代替window.jQuery...