How to use JS to get IE Upload file path (ie7,8)

Source: Internet
Author: User
This article is the use of JS to obtain IE Upload file path implementation code for a detailed analysis of the introduction, the need for friends under the reference copy code code 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 (' Please select 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;


//ie7 and IE8 get file Paths


if (isIE7 | | isIE8) {


Fileupload.select ();


filepath = Document.selection.createRange (). text;


                }


//ie6 Get file path


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 = ' <input type= ' file ' name= ' + fileupload.name + ' "id=" ' + fileupload.id + ' "Onchang E= "Disablesave (this);" /> ';


alert ("File exceeds size!") ");


                    }


Else {alert ("File Upload succeeded!") "); }


                }


            }


       }

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.