JS 弹出文件保存窗口

今天在网上找到一个JS弹出文件保存窗口的代码,很是受用,分享出来,大家共同学习。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function BrowseFolder() {
		var saveFolder = "";
		var Message = "请选择保存目录";
		var Shell = new ActiveXObject("Shell.Application");
		var Folder = Shell.BrowseForFolder(0, Message, 0x0000, 0);
		if (Folder != null) {
			if (Folder == "桌面") {
				saveFolder = new ActiveXObject("wscript.shell")
						.SpecialFolders("Desktop");
			} else {
				Folder = Folder ? Folder.items().item().Path : '';
				saveFolder = (/^\w:/.test(Folder)) ? Folder : '';
			}
			saveFolder.replace("%20", " ")//把路径中的20%还原为空格""   
			alert("您保存路径为:" + saveFolder);  
		}
		return saveFolder;
	}
</script>
</head>
<body>
	<input type="button" onclick="BrowseFolder()" value="保存">
</body>
</html>
文章出自: http://061041033.iteye.com/blog/1180730

你可能感兴趣的:(js,弹出文件保存窗口)