可能重复:
上传文件时无法获取完整地址
我需要完整的道路.我正在尝试提供本地书签的功能,即用户想要访问c:\MyStuff\Myfile.xls他们的本地PC.如何保存/获取该值,而无需编写有关如何剪切和粘贴的教程帮助页面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> …Run Code Online (Sandbox Code Playgroud)