ファイルアップロード時にプログレスバーのコードを表示します.
2947 ワード
1.コードの例は以下の通りです.
<script type="text/javascript">
//
if(/android/i/.test(navigator.userAgent)) {// android
}else if(/ipad | iphone/i.test(navigator.userAgent)){// ios
//
} else {
//pc ,
}
mui.plusReady(function(){
//
function GetNetWorkState() {
var NetStateStr = ' ';
var types = {};
types[plus.networkinfo.CONNECTION_UNKNOW] = ' ';
types[plus.networkinfo.CONNECTION_NONE] = ' ';
types[plus.networkinfo.CONNECTION_ETHERNET] = ' ';
types[plus.networkinfo.CONNECTION_WIFI] = 'WiFi ';
types[plus.networkinfo.CONNECTION_CELL2G] = '2G ';
types[plus.networkinfo.CONNECTION_CELL3G] = '3G ';
types[plus.networkinfo.CONNECTION_CELL4G] = '4G ';
NetStateStr = types[plus.networkinfo.getCurrentType()];
return NetStateStr;
};
//
window.createDownload() {
if(GetNetWorkState()==" " || GetNetWorkState()==" ") {
plus.nativeUI.alert(" , ");
return;
}else if(GetNetWorkState()==" " || GetNetWorkState()=="3G " || GetNetWorkState()=="2G " || GetNetWorkState()=="4G ") {
mui.confirm(' wifi ?',' ',[' ',' '], function(e) {
if(e.index == 1) {
startDownload();
}
})
}else{
startDowanload();
}
}
//
function startDownload() {
document.getElementById("jindu").style.display = "block";
document.getElementById("download").innerHTML = " ";
var dtask = plus.downloader.createDownload("utrl",{},function (d,status) {
//
if(status == 200) {
d.filename = d.filename;
document.getElementById("download").onclick = function() {
plus.runtime.openFile(d.filename);
}
} else {
plus.nativeUI.alert(" !");
}
});
//
range("url");
dtask.start();
}
//
document.getElementById('gameOver').onclick = function () {
}
var req = new XMLHttpRequest();
function range(url) {
var percentComplete;
req.addEventListener("progress", function(event) {
if(event.lengthComputable) {
percentComplete = parseFloat((event.loaded / event.total) * 100).toFixed(0);
document.getElementById('jindu').innerHTML = "(" + percentComplete +"%)";
if(document.getElementById("jindu").innerHTML == "(100%)") {
document.getElementById("download").innerHTML = " ";
document.getElementById("gameOver").style.display = "none";
}
}
},false);
req.open("GET",url);
req.send();
}
function stop() {
req.abort(); // XMLHttpRequest
window.stop();
}
});
</script>
</code></pre>
<br/>
<br/>
<p><br/></p>
</div>
</div>
</div>
</div>