2013-03-13 16 views
0

我想這樣做,我有一個帶有href attr的標籤,它在正常意義上會下載文件,但是我想在更改網頁外觀中的某些信息後進行下載在此代碼:在調用javascript函數後進行下載

這是我有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'); 
}; 

謝謝。

+0

'但我不能這樣做。「你是什麼意思?你有錯誤嗎? – 2013-03-13 15:01:34

+0

Noo,它的變化都沒有下載文件(該文件是實際頁面的pdf) – 2013-03-13 15:06:36

回答

1

改變它之後,你不能只是轉到那個URL嗎?

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

非常感謝! – 2013-03-13 15:38:13

1

如果你有文件的地址,只需打開該地址:

window.open("http://..."); 

編輯:媽的,CTRL-ALT-迪利普打我給它。

+0

那是什麼.. – 2013-03-13 15:07:24

+0

啊,我明白你的意思了。我誤解了你。給我一秒鐘。 – GJK 2013-03-13 15:08:03

相關問題