2014-11-24 44 views
1

已經寫了這段代碼,它在Google Chrome上工作完美,但不適用於Firefox,您有線索嗎?JavaScript上的文件下載在Firefox上不起作用

預期的行爲是,您將xml文本和名稱作爲參數傳遞,並使用該xml文本和您發送的名稱下載xml文件,如我所說,對於Chrome而言,對於Firefox而言,它確實可行不下載它。

/** * 創建並從查詢選定的行下載文件導致 * @參數XMLTEXT * @參數文件名 */

功能createAndDownloadFile(XMLTEXT,文件名){

var pom = document.createElement('a'); 
//creates a blob variable with the xml text 
var bb = new Blob([xmltext], {type: 'text/xml'}); 

//sets the atribute href 
pom.setAttribute('href', window.URL.createObjectURL(bb)); 
pom.setAttribute('download', filename); 

//creates the download url 
pom.dataset.downloadurl = ['text/xml', pom.download, pom.href].join(':'); 
pom.draggable = true; 
pom.classList.add('dragout'); 

//apply the click on to download the file 
pom.click(); 

}

回答

1

我剛回答說,我在這裏計算器一個非常類似的問題:Download attribute not working in Firefox

嘗試點擊事件之前添加元素的DOM:

//apply the click on to download the file 
document.body.appendChild(pom); 
pom.click(); 
document.body.removeChild(pom); 
+0

你好MattSidor工作只是完美的我,非常感謝你的幫助。 – 2014-11-25 14:02:30

+0

很高興聽到它。你能幫我一個忙嗎?點擊答案左邊的綠色複選標記,告訴其他人它回答了你的問題?非常感謝! – MattSidor 2014-11-25 17:19:15

相關問題