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>

    图示:

  • 相关阅读:
    C++11学习笔记
    孙鑫MFC学习笔记20:Hook编程
    孙鑫MFC学习笔记19:动态链接库
    孙鑫MFC学习笔记18:ActiveX
    孙鑫MFC学习笔记17:进程间通信
    孙鑫MFC学习笔记16:异步套接字
    孙鑫MFC学习笔记:15多线程
    ionic2 使用slides制作滑动效果的类型选择栏
    JavaScript简明教程之Node.js
    ionic2实战-使用Chart.js
  • 原文地址:https://www.cnblogs.com/Joans/p/2226516.html
Copyright © 2011-2022 走看看