首页 \ 问答 \ 如何使用javascript下载doc文件(How to download doc file using javascript)

如何使用javascript下载doc文件(How to download doc file using javascript)

尝试使用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>

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


I got the following error while trying to download file using java-script.

ERROR:

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>

Does anyone know how to resolve this problem? Thanks.


原文:https://stackoverflow.com/questions/4872783
更新时间:2023-05-04 18:05

最满意答案

如果没有弄错你的问题是在点击按钮后点击F5。 尝试重新提交表单是正常行为,与asp.net无关,但与浏览器无关。

F5导致重新执行服务器的最后一个请求,在您的情况下,POST请求。

避免此问题的一种方法是实现Web模式Post / Redirect / Get


If don't get you wrong your problem is when you hit F5 after clicking the button. Trying to resubmit the form is the normal behavior and is not related to asp.net but to browsers in general.

F5 causes to re-execute last request to the server, in your case, a POST request.

A way to avoid this issue is implementing the web pattern Post/Redirect/Get

相关问答

更多
  • 不幸的是,你目前的做法是死路一条。 HTTP的本质是单一请求,单一响应。 答案只能有一个代码 - “好的,这里有一些数据,请下载”。 “改为这里”是一个不同的代码。 你正在描述更复杂的事情 - 一系列指令。 首先“这里是一个文件”,然后“重定向到另一个资源”。 使这项工作的意义应该是一个线索 - 浏览器何时重定向? 当用户选择一个位置来保存文件? 文件完成下载后? 要做你正在描述的内容,你可以让JavaScript在新窗口中打开PDF并重新加载当前窗口。 Unfortunately your current ...
  • 让getData()返回false。 这将修复它。
    Let getData() return false. This will fix it.
  • 一旦页面呈现给客户端,您只有两种方式强制刷新。 一个是Javascript setTimeout("location.reload(true);", timeout); 第二个是Meta标签: 您可以在服务器端设置刷新间隔。 Once the page is rendered to the client you have only two ways of forcing a refresh. One is Javascr ...
  • 这里有两种方法......一种使用触发器,另一种使用SqlDependency。 我建议使用SqlDependency,但我概述了另一种方法,因为你指出了SqlDependency的问题。 创建一个包含表名和上次更新日期列的表。 在tblEmployee上创建一个触发器,以在任何insert / update / delete上更新该表。 加载页面时,您需要存储表的当前上次更新日期。 根据页面的设置方式,您可以将其存储在ViewState中或作为页面上的隐藏字段存储。 然后,您需要轮询更改。 有很多方法可以 ...
  • 这是一个共同的问题。 行为是设计的:当刷新页面时,按下的按钮的信息实际上被重新发送到服务器(以及控件的所有其他信息)。 一个很好的解决方法我发现,在网上冲浪时(这种方式在服务器端)使用HashTable: //Class member HashTable ht = new HashTable(); btnMyButton_Click(object sender, EventArgs e) { ht =(Hashtable)Application["UserOKHashtable"] ...
  • 我会将控件放置在“更新”面板中。 为此,您还需要一个位于其上的脚本管理器,如下所示:
  • 默认情况下,UpdatePanel只会在其中的对象触发各种事件时触发刷新。 您需要在UpdatePanel中移动ModalPopupExtender和代码,或者在模态弹出框中指定附加到Ok按钮的更新触发器。 如果你还没有得到适当的刷新,你可能需要添加一个myUpdatePanel.Update()命令到你的确定按钮的代码来刷新面板,你已经提供了新的LinkButton的内容。 By default, the UpdatePanel will only trigger refreshes when objec ...
  • 我想你可能可能正在使用一个较旧的jQuery版本。尝试使用greater than 1.8配合版本,然后检查它。尝试使用你的代码伙伴制作的小提琴.. :) 的jsfiddle http://jsfiddle.net/Q2gJD/ I think u might be probably using an older jQuery version.Try using version greater than 1.8 mate and then check it out.Try the fiddle made u ...
  • 如果没有弄错你的问题是在点击按钮后点击F5。 尝试重新提交表单是正常行为,与asp.net无关,但与浏览器无关。 F5导致重新执行服务器的最后一个请求,在您的情况下,POST请求。 避免此问题的一种方法是实现Web模式Post / Redirect / Get If don't get you wrong your problem is when you hit F5 after clicking the button. Trying to resubmit the form is the normal b ...
  • 这不行。 您已经编写了在代码隐藏文件中绑定gridview的逻辑。 为了执行代码隐藏文件,页面需要刷新(回发后) 您可以停止按钮刷新页面( onclick = "return false;" ),但这不会在服务器上执行您的点击事件。 你需要重新思考你的方法。 在jQuery对话框上运行gridview的一种方法是你可以在页面上设置一个隐藏变量(表示单击该按钮),然后在文档就绪中你可以打开jQuery对话框。 $(document).ready(function(){ // if flag == true ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)