How to Use JS to obtain the path (IE7, 8) _ javascript

Source: Internet
Author: User
This article provides a detailed analysis of the implementation code for getting the path of the IE uploaded file using JS. For more information, see The Code is as follows:


Function validateFileSize (id, maxsize ){
Var btnsave = document. getElementById ("Button2 ");
Btnsave. disabled = false;
Var filepath = "";
Var fileupload = document. getElementById (id );
If (fileupload. value. length <5) {alert ('select a file! '); Return ;}
Var agent = window. navigator. userAgent;
If (document. all ){
Var isIE7 = agent. indexOf ('msie 7.0 ')! =-1;
Var isIE8 = agent. indexOf ('msie 8.0 ')! =-1;
// Obtain the file path from IE7 and IE8
If (isIE7 | isIE8 ){
Fileupload. select ();
Filepath = document. selection. createRange (). text;
}
// Obtain the file path from IE6
Else
{Filepath = file. value ;}
// PageMethods. ValidateFile (filepath, maxsize, ieCallBack );
Alert (filepath );
}
If (agent. indexOf ("Firefox")> = 1 ){
Alert ("FF ");
Alert (getValue ());
Return false;
If (fileupload. files ){
Var size = fileupload. files [0]. fileSize;
If (size> parseInt (maxsize )){
Fileupload. parentNode. innerHTML ='';
Alert ("the file size exceeds! ");
}
Else {alert ("File Uploaded successfully! ");}
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.