<html>
<head>
<title>Untitled Page</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('Unable to access local files due to browser security settings. To overcome this, follow these steps: (1) Enter "about:config" in the URL field; (2) Right click and select New->Boolean; (3) Enter "signed.applets.codebase_principal_support" (without the quotes) as a new preference name; (4) Click OK and try loading the file again.');
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;
}
if ( file.exists() == false ) {
alert("File '" + fileName + "' not found.");
return;
}
alert(file.path); // I test to get the local file's path.
var is = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance( Components.interfaces.nsIFileInputStream );
try { is.init( file,0x01, 00004, null); }
catch (e) {
if (e.result!=Components.results.NS_ERROR_FILE_ACCESS_DENIED) throw e;
alert("Unable to access local file '" + fileName + "' because of file permissions. Make sure the file and/or parent directories are readable.");
return;
}
var sis = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance( Components.interfaces.nsIScriptableInputStream );
sis.init( is );
var data = sis.read( sis.available() );
var s = file.path; //文件路径
//s += "建立时间: " + Date.parse(file.DateCreated) + " ";
//s += "最后访问时间: " + Date.parse(file.DateLastAccessed) + " ";
//s += "最后修改时间: " + Date.parse(file.DateLastModified) ;
alert("Data from file: " + data); // I test to get the local file's data.
}
function readFileIE(fileBrowser) {
var data ,f,s;
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fileName=fso.GetAbsolutePathName(fileBrowser.value);
if (!fso.FileExists(fileName)) {
alert("File '" + fileName + "' not found.");
return;
}
f = fso.GetFile(fileName); // filespec 是指定文件的路径(绝对和或相对的),必选项。
s = f.Path.toUpperCase() + "<br>"; //文件路径
s += "建立时间: " + Date.parse(f.DateCreated) + " ";
s += "最后访问时间: " + Date.parse(f.DateLastAccessed) + " ";
s += "最后修改时间: " + Date.parse(f.DateLastModified) ;
// var file = fso.OpenTextFile(fileName, 1);
//data = file.ReadAll();
alert("Data from file: " + s);
f.Close();
}
catch(e) {
if (e.number == -2146827859) {
// This is what we get if the browser's security settings forbid
// the use of the FileSystemObject ActiveX control
alert('Unable to access local files due to browser security settings. To overcome this, go to Tools->Internet Options->Security->Custom Level. Find the setting for "Initialize and script ActiveX controls not marked as safe" and change it to "Enable" or "Prompt"');
}
else if (e.number == -2146828218) {
// This is what we get if the browser can't access the file
// because of file permissions
alert("Unable to access local file '" + fileName + "' because of file permissions. Make sure the file and/or parent directories are readable.");
}
else throw e;
}
}
</script>
</head>
<body>
<form name="form1">
Browse to select a file
<input type="file" name="fileBrowser" size="125" onchange="readFile(this)" />
</form>
</body>
</html>
分享到:
相关推荐
要实现Firefox对ActiveX控件的支持,必须解决四个问题,包括如何创建...化控件对象,如何在Firefox浏览器中显示和现场激活控件,如何使JavaScript能访问控 件的属性和方法以及如何捕获控件事件并将其转发给JavaScnpt。
标题中的“Firefox支持ActiveX控件”涉及到的是网络浏览器Firefox与ActiveX技术的交互。ActiveX是由微软开发的一种技术,主要用于Internet Explorer,它允许在网页上嵌入各种控件,如媒体播放器、PDF阅读器等,以...
### 关于火狐3和IE无法浏览文件全路径问题 #### 背景与概述 在现代Web开发中,浏览器为了提高安全性,通常限制了直接访问本地文件的能力。特别是对于像Internet Explorer(IE)和早期版本的Mozilla Firefox这类较...
用户可以在Firefox中使用这个扩展来管理已支持的ActiveX控件,包括查看控件的CLSID、ProgID、版本号和安装路径,并指定要支持或禁用的控件。该扩展的用户界面采用XUL开发,底层功能则由JavaScript和XPCOM组件实现。 ...
这通常涉及到在服务器端部署ActiveX Bridge,并在客户端的火狐浏览器中进行配置,确保浏览器能够正确识别并加载这个桥梁。 具体实现步骤可能包括: 1. 安装并配置支持NPAPI或ActiveX Bridge的插件。 2. 在服务器端...
在IT领域,尤其是在Web开发和浏览器扩展中,Firefox(火狐)作为一个开源且跨平台的浏览器,有时需要与本地系统进行交互,例如调用DLL(动态链接库)文件。DLL文件通常包含可重用的代码和数据,允许多个程序共享同一...
文章中提到的是在隐藏input file的情况下,如何在不同的浏览器中获取file控件的值,即用户选定文件的完整路径。 首先,需要了解的是,file控件的value属性通常仅包含文件的名称,而不包含完整路径。但是一些旧版的...
2. **利用File对象的name属性**:虽然不能获取完整路径,但可以通过`File`对象的`name`属性获取到文件名,这在某些情况下已经足够了。 3. **使用FormData上传文件**:在需要将文件上传到服务器的情况下,可以创建一...
11. **服务器端组件**:除了客户端控件,ntko还提供服务器端组件来处理上传的文件,如保存、重命名、移动、删除等操作,同时可以进行权限控制和日志记录。 12. **用户体验优化**:控件支持自定义上传界面,开发者...
在IE浏览器中,OCX插件是非常常见的,但因为安全性和兼容性问题,其他浏览器如Firefox并不默认支持。 描述中提到的“在FireFox中注册axhost.r39.xpi,然后安装ffactivex-setup-r39.exe”,这是一套步骤来使Firefox...
标题中的“让FireFox支持OCX插件的安装包”指的是通过特定的手段使得Mozilla Firefox浏览器能够识别并运行OCX(Object Control Extension)插件。OCX插件是微软Windows平台下的一种ActiveX技术,主要用于扩展应用...
selenium为firefox设置下载文件的保存,很好地解决了默认路径问题
### 解决AjaxFileUpload.js在IE9与Firefox下文件过大导致无效问题 #### 背景介绍 在处理Web前端的文件上传功能时,我们经常会遇到浏览器兼容性问题,尤其是在处理较旧版本浏览器如IE9及Firefox时。本文将详细介绍...
### Firefox无法正常浏览JSP与ASP文件的解决方法 #### 问题概述 Firefox浏览器作为一种流行的开源浏览器,在使用过程中可能会遇到一些兼容性问题。其中一种常见问题是,在尝试访问以JSP(JavaServer Pages)或者ASP...
Firefox 29 - 完整包,下载后直接就能用,新手或懒得折腾的直接下载这个就行了 全新的重要自定义模式可轻松个性化您的Web体验,以访问您最常用的功能 Firefox的右上角有一个易于访问的新菜单,其中包含流行的...
在早期版本的Firefox(例如18.0)中,当用户选择文件后,开发者可以通过`input`元素的`files`属性获取到`File`对象,而`File`对象的`name`属性则提供了文件的相对路径。然而,出于安全考虑,现代浏览器(包括Firefox...
免费 您当前运行的不是Firefox浏览器,您可以点击“安装到Firefox”按钮下载该文件,然后直接拖入到Firefox窗口中(或者在Firefox浏览器地址栏中输入该文件完整路径文件名),即可执行安装过程。 温馨提示:若安装...
以北恩U800耳式电话为例 准备: 在ocx文件夹中有以下文件...U800ocx - firefox.html 支持firefox的调用ocx控件的html文件 TypeLibraryExplorer.rar ocx文件查看器 FFOCX.zip 让FireFox支持OCX插件的安装包
标题"javascript日期控件兼容FireFox修改版(二)"指出,这是一个关于解决JavaScript日期控件在Firefox浏览器中兼容性问题的解决方案。 描述中提到的"修改后版本存在BUG",暗示了原始的日期控件代码在Firefox上可能...
标题中的“兼容火狐浏览器的js中文日历控件”意味着这个控件专门设计来解决火狐浏览器可能存在的兼容性问题。Firefox(火狐)与其他主流浏览器如Chrome、Safari和Edge有着不同的内核,因此某些JavaScript代码在不同...