本文介绍了FireFox中的window.open问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在Firefox下载文件的问题。我试图找到解决旧帖子,但我没有找到任何东西。我明白这个解决方案非常简单,但是我认为今天不是我的幸运日:)

简单的例子。我尝试从JavaScript调用Web方法并下载文件。

客户端代码:

 < script language =javascripttype =text / javascript> 
函数Test(){
PageMethods.Test(onCompleted);


function onCompleted(result){
window.open(result);
}
< / script>

...

< asp:ScriptManager ID =ScriptManagerrunat =serverEnablePageMethods =true>
< / asp:ScriptManager>

< div>
< input type = button value =Downloadonclick =Test()/>

< / div>

服务器端:

  [System.Web.Services.WebMethod] 
public static string Test()
{
return\\Files\\test.zip;

$ / code>

文件夹'文件'位于Web应用程序的根文件夹中。



对于IE和Chrome,这个代码工作正常,我可以下载文件。但在Firefox中,出现错误:
$ b

和url我可以看到例如:
\Files\test.zip



如何将正确的路径返回给zip文件?

解决方案

URL不允许反斜杠。

如果该文件位于您的Windows Web服务器根目录\F​​iles\test.zip上,则该文件的正确URL为http:///Files/test.zip

I have problem with downloading files in Firefox. I tried to find solution in old posts but I didn't find anything. I understand that solution is very simple, but I think today is not my lucky day :)

Simple example. I try to call a web method from JavaScript and download a file.

Client code:

 <script language="javascript" type="text/javascript">
         function Test() {
             PageMethods.Test(onCompleted);
         }

         function onCompleted(result) {
             window.open(result);
         }
    </script>

........

 <asp:ScriptManager ID="ScriptManager" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>

    <div>
     <input type=button value="Download" onclick="Test()"/>

    </div>

Server side:

[System.Web.Services.WebMethod]
public static string Test()
{
  return "\\Files\\test.zip";
}

Folder 'Files' lies in root folder of Web application.

For IE and Chrome, this code is working fine, and I can download the file. But in Firefox, I get an error:

and in url I can see for example:http://localhost:1406/\Files\test.zip

How can I return the correct path to zip file?

解决方案

URL don´t allow for backslashes.

If the file is located at \Files\test.zip on your windows webserver root the correct url to the file is http:///Files/test.zip

这篇关于FireFox中的window.open问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:57