由于小弟对于JavaScript,还是认识潜的,想请高人帮忙,怎样可以修改,令到以下的上传进程,当上传物件到100%成功,弹出新的窗口,取得分享的连接。谢谢先的!!<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<title>File Upload Progress</title>
<Script language="JavaScript">
var interval = null;
var pause=1000;
var time_start = (new Date()).getTime();
var total=0;
var errors=0;
var size_old;
function $(x){return document.getElementById(x)}
function xset(id,value)
{
if($(id))$(id).innerHTML = value;
}
function convertSeconds(seconds)
{
var secs = seconds % 60;
var mins = ((seconds - secs) % 3600) / 60;
var hours = ((seconds - secs - mins*60) % 86400) / 3600;
if(hours>0)
{
return hours+' hours '+mins+' minutes';
}
else if(mins>0)
{
return mins+' minutes '+secs+' seconds';
}
else
{
return secs+' seconds';
}
}
function convertSize(size)
{
if (size > 1024*1024*1024) {
size = Math.round(size/(1024*1024*1024)*10)/10 + " Gb";
} else if (size > 1024*1024) {
size = Math.round(size/(1024*1024)*10)/10+'';
if(!size.match(/\./))size+='.0';
size+=' Mb';
} else if(size > 1024) {
size = Math.round(size/1024*10)/10 + " Kb";
} else {
size = size + " Bytes";
}
return size;
}
function SP(cursize,totalsize,speed,estimate,files)
{
var percent = parseInt(100*parseFloat(cursize)/parseFloat(totalsize));
$('upload_status').style.width = percent+'%';
xset('percent', percent+'%' );
xset('cursize', convertSize(cursize) );
xset('totalsize', convertSize(totalsize) );
xset('speed',speed);
xset('estimate', convertSeconds(estimate) );
}function jah(uid)
{
if(errors>15){window.clearTimeout(interval);}
var req;
if(window.XMLHttpRequest)
{
req = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
try {req = new ActiveXObject("Msxml2.XMLHTTP");} catch(e)
{
try {req = new ActiveXObject("Microsoft.XMLHTTP");} catch(e) {return 0;}
}
}
else {return 0;} var speed = 0;
var time_left =0;
req.open("GET", uid+".html?"+Math.random(), 1);
req.onreadystatechange = function()
{
if(req.readyState == 4)
{
if (req.status == 200)
{
var res = req.responseText;
if(res==''){ errors+=1;window.setTimeout(function (){jah(uid);},100); }
if(!res.match(/^new.+\)$/)){errors+=1;return true;}
var upload = eval(res);
if (upload.state == 'uploading')
{
if(upload.received==size_old)
{
errors+=1;
}
else
{
size_old=upload.received;
errors=0;
}
if(total>upload.size)
{
SP(total, total, 0, 0);
$('progress_info').style.display='none';
$('msg').innerHTML = 'Generating links...';
return;
}
speed = 1000*upload.received / ((new Date()).getTime() - time_start);
est = Math.round( (upload.size-upload.received)/speed );
speed = Math.round(speed / 1024);
if(!total){total=upload.size;$('progress_info').style.display='block';$('msg').innerHTML='';}
SP(upload.received, upload.size, speed, est);
}
else if (upload.state == 'done')
{
SP(upload.size, upload.size, 0, 0);
$('progress_info').style.display='none';
$('msg').innerHTML = 'Generating links...';
window.clearTimeout(interval);
}
else if (upload.state == 'error')
{
$('msg').innerHTML = upload.msg;
window.clearTimeout(interval);
loc = top.window.location+'';
top.location = loc.split('?')[0] + '?msg='+upload.msg;
}
}
else
{
errors+=1;
}
}
};
req.send("");
};
var aa = location.search.substring(1).split('=');
var uid = aa[0];
var site_url = 'http://'+aa[2]+'/?'+Math.random();
window.onload=function(){xset('fnames',unescape(aa[1]));}
interval = window.setInterval(function (){jah(uid);},pause);
</Script>
<Style>
body {background-color:red; font: 13px Arial; padding: 2px;}
a {color:#44b;text-decoration:none;}
#onoff {width:90%;text-align:right;color:#777;font-size:11px;}
#bar1 {width:90%;position:relative;line-height:1em;text-align: left;border: 1px solid #a3a3a3; background-color: #f6f6f6; margin-bottom:5px;}
#upload_status {height: 1.5em; width: 0%; background-color: #c9c9c9;}
#bar2 {position: absolute; text-align: center; padding-top: .25em;width:100%;top:0;left:0;font-weight:bold;}
#msg {margin-top:15px;font-weight:bold;font-style:italic;}
#progress_info {display:none;}
</Style>
</head>
<BODY topmargin=3 leftmargin=0 MARGINHEIGHT=0 MARGINWIDTH=0>
<Center><div id="onoff">progress <a href="#" title="on" onClick="if(this.innerHTML=='on'){this.innerHTML='off';window.clearTimeout(interval);}else{this.innerHTML='on';interval=window.setInterval(function (){jah(uid);},pause);}">on</a></div><div id="bar1">
<div id="upload_status"></div>
<div id="bar2"><span id='percent'>0%</span></div>
</div><div id="progress_info">
<p><b id='fnames'></b></p>
<b><span id='cursize'></span></b> from <b><span id='totalsize'></span></b><br><br>Upload speed: <b><span id='speed'></span> KB/Sec</b> <br>Time remaining: <b><span id='estimate'></span></b>
<br><br><a href="#" onClick="window.clearInterval(interval);top.location=site_url;">Abort Upload</a>
</div>
<div id='msg'>Initializing upload...</div>
</Center>
</BODY>
</HTML>
<head>
<title>File Upload Progress</title>
<Script language="JavaScript">
var interval = null;
var pause=1000;
var time_start = (new Date()).getTime();
var total=0;
var errors=0;
var size_old;
function $(x){return document.getElementById(x)}
function xset(id,value)
{
if($(id))$(id).innerHTML = value;
}
function convertSeconds(seconds)
{
var secs = seconds % 60;
var mins = ((seconds - secs) % 3600) / 60;
var hours = ((seconds - secs - mins*60) % 86400) / 3600;
if(hours>0)
{
return hours+' hours '+mins+' minutes';
}
else if(mins>0)
{
return mins+' minutes '+secs+' seconds';
}
else
{
return secs+' seconds';
}
}
function convertSize(size)
{
if (size > 1024*1024*1024) {
size = Math.round(size/(1024*1024*1024)*10)/10 + " Gb";
} else if (size > 1024*1024) {
size = Math.round(size/(1024*1024)*10)/10+'';
if(!size.match(/\./))size+='.0';
size+=' Mb';
} else if(size > 1024) {
size = Math.round(size/1024*10)/10 + " Kb";
} else {
size = size + " Bytes";
}
return size;
}
function SP(cursize,totalsize,speed,estimate,files)
{
var percent = parseInt(100*parseFloat(cursize)/parseFloat(totalsize));
$('upload_status').style.width = percent+'%';
xset('percent', percent+'%' );
xset('cursize', convertSize(cursize) );
xset('totalsize', convertSize(totalsize) );
xset('speed',speed);
xset('estimate', convertSeconds(estimate) );
}function jah(uid)
{
if(errors>15){window.clearTimeout(interval);}
var req;
if(window.XMLHttpRequest)
{
req = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
try {req = new ActiveXObject("Msxml2.XMLHTTP");} catch(e)
{
try {req = new ActiveXObject("Microsoft.XMLHTTP");} catch(e) {return 0;}
}
}
else {return 0;} var speed = 0;
var time_left =0;
req.open("GET", uid+".html?"+Math.random(), 1);
req.onreadystatechange = function()
{
if(req.readyState == 4)
{
if (req.status == 200)
{
var res = req.responseText;
if(res==''){ errors+=1;window.setTimeout(function (){jah(uid);},100); }
if(!res.match(/^new.+\)$/)){errors+=1;return true;}
var upload = eval(res);
if (upload.state == 'uploading')
{
if(upload.received==size_old)
{
errors+=1;
}
else
{
size_old=upload.received;
errors=0;
}
if(total>upload.size)
{
SP(total, total, 0, 0);
$('progress_info').style.display='none';
$('msg').innerHTML = 'Generating links...';
return;
}
speed = 1000*upload.received / ((new Date()).getTime() - time_start);
est = Math.round( (upload.size-upload.received)/speed );
speed = Math.round(speed / 1024);
if(!total){total=upload.size;$('progress_info').style.display='block';$('msg').innerHTML='';}
SP(upload.received, upload.size, speed, est);
}
else if (upload.state == 'done')
{
SP(upload.size, upload.size, 0, 0);
$('progress_info').style.display='none';
$('msg').innerHTML = 'Generating links...';
window.clearTimeout(interval);
}
else if (upload.state == 'error')
{
$('msg').innerHTML = upload.msg;
window.clearTimeout(interval);
loc = top.window.location+'';
top.location = loc.split('?')[0] + '?msg='+upload.msg;
}
}
else
{
errors+=1;
}
}
};
req.send("");
};
var aa = location.search.substring(1).split('=');
var uid = aa[0];
var site_url = 'http://'+aa[2]+'/?'+Math.random();
window.onload=function(){xset('fnames',unescape(aa[1]));}
interval = window.setInterval(function (){jah(uid);},pause);
</Script>
<Style>
body {background-color:red; font: 13px Arial; padding: 2px;}
a {color:#44b;text-decoration:none;}
#onoff {width:90%;text-align:right;color:#777;font-size:11px;}
#bar1 {width:90%;position:relative;line-height:1em;text-align: left;border: 1px solid #a3a3a3; background-color: #f6f6f6; margin-bottom:5px;}
#upload_status {height: 1.5em; width: 0%; background-color: #c9c9c9;}
#bar2 {position: absolute; text-align: center; padding-top: .25em;width:100%;top:0;left:0;font-weight:bold;}
#msg {margin-top:15px;font-weight:bold;font-style:italic;}
#progress_info {display:none;}
</Style>
</head>
<BODY topmargin=3 leftmargin=0 MARGINHEIGHT=0 MARGINWIDTH=0>
<Center><div id="onoff">progress <a href="#" title="on" onClick="if(this.innerHTML=='on'){this.innerHTML='off';window.clearTimeout(interval);}else{this.innerHTML='on';interval=window.setInterval(function (){jah(uid);},pause);}">on</a></div><div id="bar1">
<div id="upload_status"></div>
<div id="bar2"><span id='percent'>0%</span></div>
</div><div id="progress_info">
<p><b id='fnames'></b></p>
<b><span id='cursize'></span></b> from <b><span id='totalsize'></span></b><br><br>Upload speed: <b><span id='speed'></span> KB/Sec</b> <br>Time remaining: <b><span id='estimate'></span></b>
<br><br><a href="#" onClick="window.clearInterval(interval);top.location=site_url;">Abort Upload</a>
</div>
<div id='msg'>Initializing upload...</div>
</Center>
</BODY>
</HTML>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货