<输入类型='文件'>IE 给出完整路径,FF 只给出文件名(或目录浏览) [英] <input type='file'> IE Gives full path, FF gives only filename (or directory browse)

查看:28
本文介绍了<输入类型='文件'>IE 给出完整路径,FF 只给出文件名(或目录浏览)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
上传文件时无法获取完整地址

我需要完整路径.我正在尝试提供本地书签的功能,即用户希望在其本地 PC 上访问 c:MyStuffMyfile.xls.如何保存/获取该值而不必制作有关如何剪切和粘贴 c:MyStuffMyfile.xls 的教程帮助页面.

I need the full path. I'm trying to give the functionality of local bookmarks, ie user wants to access c:MyStuffMyfile.xls on their local Pc. How do I save/get that value without having to make a tutorial help page on how to cut and paste c:MyStuffMyfile.xls .

以下代码适用于 IE7.我明白这是一个安全问题,但我不需要保存他们的选择,甚至不需要使用 enctype/multiform,甚至不需要提交任何东西,我只需要获取他们选择的路径.

The below code works in IE7. I understand the point about it being a security issue, but I don't need to save their choice or even use enctype/multiform, or even submit anything, i just need to get the path they selected.

<html>

<head>
  <title></title>
</head>

<body>
<script language="JavaScript" type="text/javascript">
<!--
vic=0;
document.write('<style> .debug {VISIBILITY: visible; POSITION: absolute; TOP: 500px; z-Index:100; }</style>')
<!---->
</script>

Select a file from directory then save the path<br>
<input type="file" id="dir" value="dir" style="width:0px;" >
<input type="button" value="Save Path" onclick="javascript:SavePath();" >

<script language="JavaScript" type="text/javascript">
<!-- works on ie8 not ff.
function SavePath(){
if (document.getElementById('dir').value==''){
  alert('Select a file from the directory');
  return;
}
Path=document.getElementById('dir').value.substring(0,document.getElementById('dir').value.lastIndexOf('\'));
alert('variable Path='+Path+'\ ');
}
//-->
</script>
</body>

</html> 

推荐答案

我需要完整路径.

I need the full path.

你不会得到它!

抱歉,没有办法.

(您根本不能依赖文件名中的任何有用内容:即使浏览器包含整个路径,如果它不是 Windows 框,您也不会获得 \ 路径分隔符.你可能会得到 /... 或者其他的东西.)

(You can't rely on anything useful being in the filename at all: even if the browser includes the whole path, if it ain't a Windows box you're not going to get \ path-separators. You might get /... or something else completely.)

如何在无需制作关于如何剪切和粘贴的教程帮助页面的情况下保存/获取该值

How do I save/get that value without having to make a tutorial help page on how to cut and paste

您可以尝试鼓励他们将文件图标拖放到一个简单的文本字段中.在许多浏览器中会粘贴路径名.

You could try encouraging them to drag-and-drop the file icon to a simple text field. In many browsers that will paste in the pathname.

language="JavaScript"

language="JavaScript"

你不需要那个.

javascript:

你不需要那个.

<!--
    ...
<!---->

你不需要那个.(如果这样做,不匹配的 -- 将无效.)

You don't need that. (And if you did, the mismatched --s would be invalid.)

<!-- works on ie8 not ff.

不正确的 JavaScript 注释.

Not properly a JavaScript comment.

这篇关于&lt;输入类型='文件'&gt;IE 给出完整路径,FF 只给出文件名(或目录浏览)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆