zoukankan      html  css  js  c++  java
  • 上传文件框在firefox浏览器中显示路径不全的解决方法

    记录下firefox浏览器中上传文件框显示路劲不全的解决办法。

    html文本:

    <div>

       <span style="font-size: 15px; margin-left:200px;">导入</span>
            <input type="file" name="picpath" id="picpath" style="display: none" onchange="picpathchange()"/>
            <input name="path" id="path" readonly="readonly" style = "350px;font-size: 15px;height: 35px;"  class="bigTextBox" />
            <input type="button" value="浏览..." onclick="picpathclick()" class="whiteBtn" />

    </div>

    js代码

    <script type="text/javascript">

    function picpathchange() {
            $("#path").html("");
            $("#path").val(FilePath.getFilePath(document.getElementById("picpath")));
        }
        function picpathclick() {
            $("#picpath").val("");
            $("#picpath").click();
        }
        var FilePath = {
            getFilePath: function (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 + ")");
            },
            getFilePathWithFF: function (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 {
                    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;
            }
        }

    </script>

    图示:

  • 相关阅读:
    【spring cloud】spring cloud服务发现注解之@EnableDiscoveryClient与@EnableEurekaClient
    【IntelliJ IDEA】idea导入项目只显示项目中的文件,不显示项目结构
    【IntelliJ IDEA】idea显示工具栏
    笔记:git基本操作
    Spring Boot中使用AOP统一处理Web请求日志
    Spring Boot应用的后台运行配置
    RSA加密
    Java汉字md5值不一致问题
    如何判断一个请求是不是ajax请求
    SpringBoot拦截器中service或者redis注入为空的问题
  • 原文地址:https://www.cnblogs.com/Joans/p/2226516.html
Copyright © 2011-2022 走看看