可能重复:
Can’t get the complete address while uploading a file<INPUT TYPE = '文件'> IE给出完整路径,FF仅给出文件名(或目录浏览)
我需要的完整路径。 我试图给本地书签的功能,即用户想要访问其本地电脑上的c:\MyStuff\Myfile.xls
。 如何保存/获取该值,而不必制作关于如何剪切和粘贴c:\MyStuff\Myfile.xls
的教程帮助页面。
以下代码适用于IE7。 我理解这是一个安全问题,但我不需要保存他们的选择,甚至不需要使用enctype/multiform,甚至不需要提交任何内容,我只需要获取他们选择的路径。
<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>