调用javascript函数后下载

时间:2013-03-13 14:54:43

标签: javascript jquery

我想这样做,我有一个带有href attr的标签,在正常意义上会下载一个文件,但是我想在网页上更改一些信息之后将其下载看看这段代码:

这是html,我有html,用户可以在哪里下载文件。

   <li class="imprimir"><h2><a href="javascript:descargarNoticia()" id="descargar"  >Descargar Noticia</a></h2></li>

这里的JS会改变信息,然后下载文件,但我不能这样做。

function descargarNoticia(){
$.post("http://www.xxx.com/noticia/datosUsuarios",
   function(data){
    $("#empresa").show();
    $("#email").html(data['email'])
    $("#telefono").html(data['telefono'])
    $("#direccion").html(data['direccion'])
    $("#empresa").html(data['empresa'])

    var words = $('#wrapper-960').text().split(' ').length;
    var alto=words*0.264583333;
   $("#descargar").attr("href","http://pdfcrowd.com/url_to_pdf/?width=500mm&height="+alto+"mm")
            }
           },'json');
};

感谢。

2 个答案:

答案 0 :(得分:1)

如果你有文件的地址,只需打开该地址:

window.open("http://...");
编辑:该死的,ctrl-alt-dileep打败了我。

答案 1 :(得分:1)

更改后,您是否可以转到该网址?

var URL= "http://pdfcrowd.com/url_to_pdf/?width=500mm&height="+alto+"mm";
$("#descargar").attr("href",URL)
window.location = URL;