选择文件保存路径

时间:2021-07-07 07:12:30

<input id="Button1" type="button" value="选择路径" onclick="javascript:browseFolder()"/>
<input id="show" type="text" />

<script>
function browseFolder() {
try {
var Message = "请选择路径"; //选择框提示信息
var Shell = new ActiveXObject("Shell.Application");
var Folder = Shell.BrowseForFolder(0, Message, 64, 17);//起始目录为:我的电脑
//var Folder = Shell.BrowseForFolder(0,Message,0); //起始目录为:桌面
if (Folder != null)
{
Folder
= Folder.items(); // 返回 FolderItems 对象
Folder = Folder.item(); // 返回 Folderitem 对象
Folder = Folder.Path; // 返回路径
if (Folder.charAt(Folder.length - 1) != "\\")
{
Folder
= Folder + "\\";
}
//document.getElementById(path).value = Folder;
document.getElementById("show").value=Folder;
//alert(Folder);
return Folder;
}
}
catch (e)
{
alert(e.message);
}
}

</script>

但是此方法有限制,我运行时只能适用于IE浏览器,其他的浏览器就不行了。。。