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();
}
你好MattSidor工作只是完美的我,非常感谢你的帮助。 – 2014-11-25 14:02:30
很高兴听到它。你能帮我一个忙吗?点击答案左边的绿色复选标记,告诉其他人它回答了你的问题?非常感谢! – MattSidor 2014-11-25 17:19:15