开发者

Progressbar for file uploads in chrome

开发者 https://www.devze.com 2023-03-04 11:51 出处:网络
I have a webpage which tracks the progress of a file upload. This is the html source: <form> <input type=\"hidden\" id=\"id\" name=\"开发者_C百科UPLOAD_IDENTIFIER\" value=\"4dc6f7819200e\"&g

I have a webpage which tracks the progress of a file upload. This is the html source:

<form>
    <input type="hidden" id="id" name="开发者_C百科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?

0

精彩评论

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