Chrome 中文件上传的进度条
我有一个跟踪文件上传进度的网页。这是 html 源代码:
<form>
<input type="hidden" id="id" name="UPLOAD_IDENTIFIER" value="4dc6f7819200e">
<input type="file" name="image">
<input type="submit" value="Upload file">
</form>
<div id="progress"></div>
<iframe id="upload-frame" name="upload-frame"></iframe>
这是我的 javascript(我使用 jQuery):
var pbar = $("#progress");
var started = false;
$(function() {
$("form").submit(function() {
pbar.show().progressbar();
$("#upload-frame").load(function() {
started = true;
}
setTimeout(function() {
updateProgress($("#id").val());
}, 500);
});
});
function updateProgress(id) {
$.get("my/url/here?id=" + id, function(progress) {
if (null === progress) {
updateProgress(id);
}
if (progress<100 || !started) {
started = progress < 100;
updateProgress(id);
}
started && pbar.progressbar('value', progress);
}
};
我将服务器端代码保留在外面,因为这是奇怪的事情:Firefox 和 IE 正常工作。只有 webkit 浏览器(Chrome、Chromium、Safari)显示进度条的开始,但不更新它们。这是为什么?有什么想法吗?
I have a webpage which tracks the progress of a file upload. This is the html source:
<form>
<input type="hidden" id="id" name="UPLOAD_IDENTIFIER" value="4dc6f7819200e">
<input type="file" name="image">
<input type="submit" value="Upload file">
</form>
<div id="progress"></div>
<iframe id="upload-frame" name="upload-frame"></iframe>
And this is my javascript (I use jQuery):
var pbar = $("#progress");
var started = false;
$(function() {
$("form").submit(function() {
pbar.show().progressbar();
$("#upload-frame").load(function() {
started = true;
}
setTimeout(function() {
updateProgress($("#id").val());
}, 500);
});
});
function updateProgress(id) {
$.get("my/url/here?id=" + id, function(progress) {
if (null === progress) {
updateProgress(id);
}
if (progress<100 || !started) {
started = progress < 100;
updateProgress(id);
}
started && pbar.progressbar('value', progress);
}
};
I leave the server side code out, because this is the strange thing: Firefox and IE work normally. Only the webkit browsers (Chrome, Chromium, Safari) show the start of the progressbar, but do not update them. Why is that? Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论