js上传文件类

var jsUpload = new function(){
	this.hiddenFrameId = 'js_upload_frame';
	this.uploadCallBack;
	this.getHiddenFrame = function(){
		if(this.loginWin==null){
			this.loginWin=document.getElementById(this.hiddenFrameId);
		}
		if(this.loginWin==null){
			var div=document.createElement("div");
			div.id="material_upload_frame_container";
			div.style.display="none";
			document.body.appendChild(div);
			var frameHtml='<iframe name="'+this.hiddenFrameId+'" id="'+this.hiddenFrameId+'" ';
			frameHtml+='width=0 height=0 style="display:none;" οnlοad="jsUpload.frameCallback()"></iframe>';
			div.innerHTML=frameHtml;
			this.loginWin=document.getElementById(this.hiddenFrameId);
		}
		return this.loginWin
	}
	this.frameCallback = function(json){
		var logWin=document.getElementById(this.hiddenFrameId),response="";
		if(json){
			response=json
		}else{
			try{
				response=logWin.contentWindow.document.body.innerHTML
			}catch(e){
				location.reload()
			}
		}
		if(response!=""&&response.length<6000){
			pos1=response.indexOf("{");
			pos2=response.lastIndexOf("}");
			if(pos1>=0&&pos2>0){
				response=response.substring(pos1,pos2+1)
			}else{
				response="{}"
			}
			var result={},param={};
			response=response.replace(/\r/g,"").replace(/\n/g,"");
			try{
				eval("result="+response)
			}catch(e){
			}
			if (typeof this.uploadCallBack=='function') {
				this.uploadCallBack(result);
			} else {
				if(result['errno']!=0){
					alert(result['errmsg']);
				}
			}
		}
	}
	this.setUploadCallBack = function(func){
		this.uploadCallBack = func;
	}
	this.upload = function(form, callback){
		if (typeof callback=='function'){
			this.setUploadCallBack(callback);
		}
		this.getHiddenFrame();
		form.target = this.hiddenFrameId;
		form.submit();
	}
};


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值