日期:2014-05-18 浏览次数:20774 次
<html>
<head>
<title>JS获取上传文件的绝对路径,兼容IE和FF</title>
<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) {
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;