html5 href下载属性问题

时间:2014-05-27 09:54:16

标签: javascript html5 download href

直到今天,这项工作正在Chrome上生成客户端的KML文件:

<script>
  var kmlText = 'kml code here';
  var link = document.createElement("a");
  link.setAttribute("href", 'data:text/plain,' + kmlText);
  link.setAttribute("download", "Export.kml");
  link.innerHTML = "Download KML";
  document.getElementById("myDIV").appendChild(link);
</script>

<html>
  <div id="myDIV">Download</div>
</html>

由于最近该链接会强制下载,但不会接受Chrome上的文件名和扩展名,默认为&#39; Download.txt&#39; .. 在Firefox上,它正常运行,就像之前在Chrome上一样..

Here's a fiddle

有人有线索吗?

1 个答案:

答案 0 :(得分:3)

它看起来像铬中的一个错误。我无法在桌面上重现它。

您应该在此处提交错误:https://code.google.com/p/chromium/issues/list