上传文件框在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 = "width: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>

 

图示:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值