<input type="file" id="fileBrowser" name="fileBrowser" size="50" onchange="readFile(this)" />

<script type="text/javascript"> 
function readFile(fileBrowser) { 
    if (navigator.userAgent.indexOf("MSIE")!=-1) 
        readFileIE(fileBrowser); 
    else if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Mozilla")!=-1) 
        readFileFirefox(fileBrowser); 
    else 
        alert("Not IE or Firefox (userAgent=" + navigator.userAgent + ")"); 
}

function readFileFirefox(fileBrowser) { //FF浏览器
    try { 
        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
    }  
    catch (e) { 
        alert('路径错误!'); 
        return; 
    }

var fileName=fileBrowser.value; 
    var file = Components.classes["@mozilla.org/file/local;1"] 
        .createInstance(Components.interfaces.nsILocalFile); 
    try { 
        file.initWithPath( fileName.replace(/\//g, "\\\\") ); 
    } 
    catch(e) { 
        if (e.result!=Components.results.NS_ERROR_FILE_UNRECOGNIZED_PATH) throw e; 
        return; 
    }

if ( file.exists() == false ) { 
        alert("File '" + fileName + "' not found."); 
        return; 
    } 
    alert(file.path); 
}

function readFileIE(fileBrowser) { //IE浏览器,可直接获取上传文件路径
    alert(document.getElementById("fileBrowser").value);

</script>

JS获取上传文件的绝对路径,兼容IE和FF的更多相关文章

  1. js获取上传文件的绝对路径

    在html中    <input type="file" id="importFile" />    <input type="bu ...

  2. struts2 JS获取上传文件的绝对路径,兼容IE和FF

    因为file控件上传失败后会自动清空,所以使用文本框来保存上传路径,而且在不同的浏览器下,控件的样式也需要兼容.下面是自己用到的实例 // 初始化判断浏览器的版本,根据版本的不同使用不同的样式func ...

  3. Atitit.js获取上传文件全路径

    Atitit.js获取上传文件全路径 1. 默认的value只能获取文件名..安全原因.. 1 2. Firefox浏览器的读取 1 3. Html5 的file api 2 4. 解决方法::使用a ...

  4. js获取上传文件内容(未完待续)

    js 获取上传文件的字节数及内容 <div> 上传文件 : <input type="file" name = "file" id = &qu ...

  5. js获取上传文件内容

    js 获取上传文件的字节数及内容 <div> 上传文件 : <input type="file" name = "file" id = &qu ...

  6. js 获取上传文件的字节数及内容

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. JS 获取上传文件的内容

    <div> 上传文件 : <input type="file" name = "file" id = "fileId" / ...

  8. JS获取上传文件的名称、格式、大小

    <input id="File1" type="file" onchange="checkFile(this)" /> 方式一) ...

  9. js获取上传文件个数 以及名称

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

随机推荐

  1. For Exam (Java常用设计模式) 介绍

    一 创建型模式 工厂模式(Factory): 定义一个用以创建对象的接口 抽象工厂模式(Abstract Factory): 提供一个创建一系列相关或相互依赖对象的接口 单例模式(Singleton) ...

  2. mysql 内连接 左连接 右连接 外连接

    mysql> desc student;+-------+-------------+------+-----+---------+-------+| Field | Type | Null | ...

  3. Java的加密与解密

    package com.wangbo.util; import java.security.Key; import java.security.Security; import javax.crypt ...

  4. js图片跑马灯效果

    <style. type="text/css">body{margin:0px auto; padding:0px;}ul,li{margin:0px; padding ...

  5. Java字符串处理函数

    substring() 它有两种形式,第一种是:String substring(int startIndex)第二种是:String substring(int startIndex,int end ...

  6. 原创: 开题报告中摘要部分快速将一段文字插入到word的表格中

    开题报告的摘要是表格形式,之前需要一个一个字的敲入,十分不方便修改. 所以百度了一下方法.现总结如下: 达到的效果 1 将这段文字复制粘贴到word中,在word文件中的每一个字与字之间插入空格.如何 ...

  7. 每日一笔记之3:QTconnect()

    刚学习QT的时候,跟着教程做一些简答的实验,教程简单的界面使用UI文件,直接在界面上拖一个按键,在右键go to slot,在编写槽函数. 我以前没学过C++,一直以为这个自动跳转过去的slot函数是 ...

  8. PHP 安全相关 简单知识

    概要: 1.php一些安全配置 (1)关闭php提示错误功能 (2)关闭一些“坏功能” (3)严格配置文件权限. 2.严格的数据验证,你的用户不全是“好”人 2.1为了确保程序的安全性,健壮性,数据验 ...

  9. el 和 fmt 常用

    EL表达式入门 转自 http://blog.chinaunix.net/uid-9789791-id-1997374.html 隐含对象: pageContext: pageContext对象 pa ...

  10. 获取iframe外边数据

    http://biancheng.dnbcw.info/javascript/178184.html