嘿傢伙是新來的JavaScript實際上..我試圖找到一個文件的下載時間。所以我已經確定了文件的大小,並與當前時間劃分..但它不是給我正確的結果。用javascript計算下載時間
我曾嘗試
function get_filesize(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open("HEAD", url, true); // Notice "HEAD" instead of "GET",
// to get only the header
xhr.onreadystatechange = function() {
if (this.readyState == this.DONE) {
callback(parseInt(xhr.getResponseHeader("Content-Length")));
}
};
xhr.send();
}
get_filesize("http://upload.wikimedia.org/wikipedia/commons/9/96/Google_web_search.png", function(size) {
var estimatedtime = (new Date().getTime())/size;
console.log(estimatedtime);
});
當我做這樣做我得到輸出32245538.389347337
代碼。
我期望的是在控制檯中獲得hh:mm:ss
的時間。
我怎樣才能達致這?..任何幫助將是巨大的感謝
究竟是什麼,你想在這裏算?下載速度?或者乾脆下載時間。 – itdoesntwork 2014-12-13 06:11:51