简体   繁体   中英

html5 href download attribute issue

Until today this was working on Chrome to generate a KML file client-side:

<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>

Since recently the link would force a download but wouldn't accept the filename and extension on Chrome, defaulting to 'Download.txt'.. On Firefox it is working properly, as it was before on Chrome, too..

Here's a fiddle

Does someone have a clue?

It looks like a bug in chrome. I can't reproduce it on my desktop.

You should file a bug here: https://code.google.com/p/chromium/issues/list

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM