使用 Javascript 下载文件 [英] Download a file using Javascript

查看:36
本文介绍了使用 Javascript 下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户能够从我的服务器下载这个 Excel 文件.单击下载"按钮后,必须有一种简单的方法来启动文件下载......但我不知道如何实现.

There's this Excel file I want users to be able to download from my server. There must be an easy way to initiate the download of the file after a click on the "Download" button... but I have no clue how to make that happen.

到目前为止我有这个:(VBscript 和 ASP)

I have this so far: (VBscript and ASP)

<head>
<script type="text/javascript" src="overzicht.js"></script>
</head>

Set fs=Server.CreateObject("Scripting.FileSystemObject")

    if (fs.FileExists("c:file.xls"))=true then   'fake filename D:
        response.write("<input type='button' value='Download Masterfile' class='button' onclick='exportmasterfile();' /><br />")
    else
        response.write("Masterfile not found. <br />")
    end if

    set fs=nothing

javascript 函数为空.

The javascript function is empty.

推荐答案

你不会相信这一点的.找到了...

you're not going to believe this. Found it...

function exportmasterfile()
{   var url='../documenten/Master-File.xls';    
    window.open(url,'Download');  
}

对不起各位!

这篇关于使用 Javascript 下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆