如何使用javascript下载doc文件

时间:2011-02-02 09:39:38

标签: javascript asp.net download doc

尝试使用java脚本下载文件时出现以下错误。

错误:

Internet Explorer cannot download Sample.doc from www.websitename.com.

Internet Explorer was not able to open this Internet site. The request is either unavailable or cannot be found.Please try again later.

HTML:

<html>
<head>
<script type="text/javascript" language="javascript"> 
function winopen() 
{ 
  window.open("Sample.doc","_self","fullscreen=no,toolbar=yes, width=800, height=600, menubar=yes, status=no,scroll=yes"); 
} 
</script>
</head>
<body onload="winopen();">
</body>
</html>

有谁知道如何解决这个问题? 感谢。

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

您需要将您尝试获取的资源的完整VALID URI传递给window.open函数。 例如。要从BBC网站下载样式表:

window.open("http://static.bbc.co.uk/homepage/css/bundles/domestic/main.css?661" "_self","fullscreen=no,toolbar=yes, width=800, height=600, menubar=yes, status=no,scroll=yes");

BTW http://www.websitename.com没有网站; - )

HTH。