Home > Web Front-end > JS Tutorial > body text

如何使用JS获取IE上传文件路径(IE7,8)_javascript技巧

WBOY
Release: 2016-05-16 17:29:37
Original
1475 people have browsed it
复制代码 代码如下:

function validateFileSize(id, maxsize) {
            var btnsave = document.getElementById("Button2");
            btnsave.disabled = false;
            var filepath = "";
            var fileupload = document.getElementById(id);
            if (fileupload.value.length             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和IE8获得文件路径
                if (isIE7 || isIE8) {
                    fileupload.select();
                    filepath = document.selection.createRange().text;
                }
                //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("文件超过大小!");
                    }
                    else { alert("文件上传成功!"); }
                }
            }
        }
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!