在firefox上传文件时获取全路径
function readFile(fileBrowser) { if (navigator.userAgent.indexOf("MSIE")!=-1) { return getFilePath(fileBrowser); } else if (navigator.userAgent.indexOf("Firefox")!=-1|| navigator.userAgent.indexOf("Mozilla")!=-1) { return getFilePathWithFF(fileBrowser); } else { return; } } function getFilePath(fileBrowser) { if (navigator.userAgent.indexOf("MSIE") != -1){fileBrowser.select(); return document.selection.createRange().text; } else if (navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Mozilla") != -1) return this.getFilePathWithFF(fileBrowser); else alert("Not IE or Firefox (userAgent=" + navigator.userAgent + ")"); }; function getFilePathWithFF(fileBrowser) { try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch(e) { alert('由于浏览器安全问题 请按照以下设置 [1] 地址栏输入 "about:config" ; [2] 右键 新建 -> 布尔值 ; [3] 输入 "signed.applets.codebase_principal_support" (忽略引号).'); return; } var fileName = fileBrowser.value; var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); try { // Back slashes for windows file.initWithPath(fileName.replace(/\//g, "\\\")); } catch(e) { if (e.result != Components.results.NS_ERROR_FILE_UNRECOGNIZED_PATH) throw e; alert("File '" + fileName + "' cannot be loaded: relative paths are not allowed. Please provide an absolute path to this file."); return; } return file.path; }