用javascript下载窗口

时间:2012-08-21 11:05:36

标签: javascript html javascript-events html-select

如何获取以下code.i.e的下载框,当用户点击下载超链接时,无论浏览器类型如何,都应出现下载窗口。我已尝试过以下代码

 <a href="javascript:void(0);" onclick="download_tagged_file('{{cnt.id}}');">Download</a><

EDIT

function download_tagged_file(cntid)
{
  var snddata = {};
  snddata["cntid"] = cntid;
  $.post("/tagging/download_tagged_file/", snddata, 
     function callbackHandler(data, textstatus) 
     {
        if (data.status == 1)
        {
            var url = data.filename;
            url = "http://127.0.0.1:8000" + url
           //var htm = '<iframe style="display: none;" id="if1" src="'+url+'"></iframe>';
           //alert(url);
           window.open(url, 'download_window', 'directories=0,status=0,scrollbars=0,resizeable=0,width=1,height=1,top=0,left=0');
           window.focus();
 }

1 个答案:

答案 0 :(得分:0)

我真的不知道你想做什么,有什么不对的:

<a href="http://127.0.0.1:8000/{{cnt.id}}">Download</a>

<击> 更新

您需要控制服务器端的内容处置。上面的html是你需要的,但你的服务器需要在提供文件时发送这个标题:

Content-Disposition: attachment; filename=<file name.ext>