解决火狐浏览器上传文件得到的只是一个文件名的问题

    技术2022-05-18  14

    今天搞程序,要上传图片,我的浏览器是火狐的最新版的,然后就发现<input type="file">返回的value居然是一个文件名,很不可思议,后来用IE8试了试,发现这个正常,人家得到的是一个完整路径。可是火狐的该这么解决了?百度了一下,发现下面这个方法可行:

    html:

    <span>图片上传:</span> <input id="pic" type="file" name ="pic" /> <br/> <input id="submit" type="button" name ="submit" value ="提交" /

    javascript:

    $("#submit").click(function () { //首先判断浏览器是否是火狐 if (navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Mozilla") != -1) { 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.'); } } alert($("#pic").val());

    会弹出一个提示框,选择“是”,然后挤搞定了;

    官方说火狐这是为了防止黑客攻击的加密举措,别管他什么原因,能解决就OK。


    最新回复(0)