日期:2014-05-16  浏览次数:20364 次

JS打开[保存文件对话框]出错:Automation server can't create object
本人想实现一个客户端js保存Table的数据,用户点击下载后,不提交到服务器,直接使用js读取数据后,打开保存对话框,用户输入路径和文件名然后下载。

遇到如下问题:
1、new   ActiveXObject( "MSComDlg.CommonDialog ")  
Error:Automation   server   can 't   create   object
(IE端,注册表没有问题,COMDLG32.OCX、comdlg32.dll均存在)
另外,new   ActiveXObject( "WScript.Shell ")也是同样的错误,但是new   ActiveXObject( "Scripting.FileSystemObject ")没有错误!

2、有可能是安全设置的问题么?如果是,如何修改安全设置(windows2003)

3、有其他的实现思路么?(只要不提交到服务器)



------解决方案--------------------
3种可能:
1.在运行里面执行regsvr32 scrrun.dll,如果不行,继续;
2.安装msxml3.dll,再不行,还继续
3.在internet选项里"安全"选项卡中涉及到activex的都启用,安全级别设置为 中.再不行,我也没招了.

------解决方案--------------------
用你这种方式当然会被浏览器的安全机制毙掉!

<input type=button value=保存 onclick= "document.execCommand( 'SaveAs ') " />
<input type=button value=另存为 onclick= "document.execCommand( 'Saveas ',false, 'c:\\test.htm ') " />
------解决方案--------------------
那就用FileSystemObject写你想写的内容啊。
------解决方案--------------------
梅花雪的思路可以实现LZ所需的效果,因为我也有用过,如保存EXCEL文件
------解决方案--------------------
asp.jscript

<%@LANGUAGE= "JAVASCRIPT " CODEPAGE= "65001 "%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=utf-8 " />
<title> shawl.qiu template </title>
</head>
<body>
<%
Download( "id ", "file ", "/upload/ ", false);

function Download(QueryId, FilePath, pathForCheck, Debug)
{
var Debug = false;

var QueryId = Request.QueryString(QueryId)+ " ";
var FilePath = Request.QueryString(FilePath)+ " ";

if(Debug)
{
Response.Write( " <li/> typeof(QueryId): "+typeof(QueryId));
Response.Write( " <li/> QueryId: "+QueryId);
Response.Write( " <li/> QueryId==\ "\ ": "+(QueryId== " "));
Response.Write( " <li/> QueryId==\ "undefined\ ": "+(QueryId== "undefined "));
Response.Write( " <hr/> ");

Response.Write( " <li/> typeof(FilePath): "+typeof(FilePath));
Response.Write( " <li/> FilePath: "+FilePath);
Response.Write( " <li/> FilePath==\ "\ ": "+(FilePath== " "));
Response.Write( " <li/> FilePath==\ "undefined\ ": "+(FilePath== "undefined "));
Response.Write( " <hr/> ");
}

if(QueryId== "undefined "||FilePath== "undefined ")Response.End();

switch(QueryId)
{
case "download ":
if(Debug)
{
Response.Write( " <li/> download: ");
Response.Write( " <hr/> ");
}
if(!CheckPathIn(FilePath, pathForCheck, true, Debug))Response.End();
DownloadFile(FilePath, true);
break;
}

function CheckPathIn(path, pathForCheck, bCovPath, Debug)