日期:2014-05-17  浏览次数:20479 次

firefox下怎么获取FileUpload的完整路径名
在网上找了这样的例子,将FF的signed.applets.codebase_principal_support键值修改为True仍然无法获取,总是catch后提示修改浏览器设置..
if (isFirefox = navigator.userAgent.indexOf("Firefox") >= 0) {
                try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                }
                catch (e) {
                    alert('请更改浏览器设置');
                    return;
                }
                //File1为FileUpload的控件ID
                var fname = document.getElementById("<%=File1.ClientID%>").value;
                var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
                try {
                    // Back slashes for windows
                    file.initWithPath(fname.replace(/\//g, "\\\\"));
                }
                catch (e) {
                    if (e.result != Components.results.NS_ERROR_FILE_UNRECOGNIZED_PATH) throw e;
                    alert('无法加载文件');
                    return;
                }
                alert(file.path);